mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-05-13 03:00:24 -04:00
Allow overwriting of persistence files.
This commit is contained in:
@@ -1727,14 +1727,15 @@ class writesharestofile(base.IOInstruction):
|
||||
""" Write shares to ``Persistence/Transactions-P<playerno>.data``
|
||||
(appending at the end).
|
||||
|
||||
:param: number of shares (int)
|
||||
:param: number of arguments to follow / number of shares plus one (int)
|
||||
:param: position (regint, -1 for appending)
|
||||
:param: source (sint)
|
||||
:param: (repeat from source)...
|
||||
|
||||
"""
|
||||
__slots__ = []
|
||||
code = base.opcodes['WRITEFILESHARE']
|
||||
arg_format = itertools.repeat('s')
|
||||
arg_format = tools.chain(['ci'], itertools.repeat('s'))
|
||||
|
||||
def has_var_args(self):
|
||||
return True
|
||||
|
||||
@@ -2329,16 +2329,20 @@ class sint(_secret, _int):
|
||||
return stop, shares
|
||||
|
||||
@staticmethod
|
||||
def write_to_file(shares):
|
||||
def write_to_file(shares, position=None):
|
||||
""" Write shares to ``Persistence/Transactions-P<playerno>.data``
|
||||
(appending at the end).
|
||||
|
||||
:param: shares (list or iterable of sint)
|
||||
:param shares: (list or iterable of sint)
|
||||
:param position: start position (int/regint/cint),
|
||||
defaults to end of file
|
||||
"""
|
||||
for share in shares:
|
||||
assert isinstance(share, sint)
|
||||
assert share.size == 1
|
||||
writesharestofile(*shares)
|
||||
if position is None:
|
||||
position = -1
|
||||
writesharestofile(regint.conv(position), *shares)
|
||||
|
||||
@vectorized_classmethod
|
||||
def load_mem(cls, address, mem_type=None):
|
||||
@@ -3922,13 +3926,15 @@ class _single(_number, _secret_structure):
|
||||
return stop, [cls._new(x) for x in shares]
|
||||
|
||||
@classmethod
|
||||
def write_to_file(cls, shares):
|
||||
def write_to_file(cls, shares, position=None):
|
||||
""" Write shares of integer representation to
|
||||
``Persistence/Transactions-P<playerno>.data`` (appending at the end).
|
||||
``Persistence/Transactions-P<playerno>.data``.
|
||||
|
||||
:param: shares (list or iterable of sfix)
|
||||
:param shares: (list or iterable of sfix)
|
||||
:param position: start position (int/regint/cint),
|
||||
defaults to end of file
|
||||
"""
|
||||
cls.int_type.write_to_file([x.v for x in shares])
|
||||
cls.int_type.write_to_file([x.v for x in shares], position)
|
||||
|
||||
def store_in_mem(self, address):
|
||||
""" Store in memory by public address. """
|
||||
@@ -5389,11 +5395,14 @@ class Array(_vectorizable):
|
||||
self.assign(shares)
|
||||
return stop
|
||||
|
||||
def write_to_file(self):
|
||||
def write_to_file(self, position=None):
|
||||
""" Write shares of integer representation to
|
||||
``Persistence/Transactions-P<playerno>.data`` (appending at the end).
|
||||
``Persistence/Transactions-P<playerno>.data``.
|
||||
|
||||
:param position: start position (int/regint/cint),
|
||||
defaults to end of file
|
||||
"""
|
||||
self.value_type.write_to_file(list(self))
|
||||
self.value_type.write_to_file(list(self), position)
|
||||
|
||||
def __add__(self, other):
|
||||
""" Vector addition.
|
||||
@@ -5723,13 +5732,20 @@ class SubMultiArray(_vectorizable):
|
||||
def _(i):
|
||||
self[i].input_from(player, budget=budget, raw=raw)
|
||||
|
||||
def write_to_file(self):
|
||||
def write_to_file(self, position=None):
|
||||
""" Write shares of integer representation to
|
||||
``Persistence/Transactions-P<playerno>.data`` (appending at the end).
|
||||
``Persistence/Transactions-P<playerno>.data``.
|
||||
|
||||
:param position: start position (int/regint/cint),
|
||||
defaults to end of file
|
||||
"""
|
||||
@library.for_range(len(self))
|
||||
def _(i):
|
||||
self[i].write_to_file()
|
||||
if position is None:
|
||||
my_pos = None
|
||||
else:
|
||||
my_pos = position + i * self[i].total_size()
|
||||
self[i].write_to_file(my_pos)
|
||||
|
||||
def read_from_file(self, start):
|
||||
""" Read content from ``Persistence/Transactions-P<playerno>.data``.
|
||||
|
||||
Reference in New Issue
Block a user