add SparseBlock with selected rows and columns only
SparseBlock stores only selected rows and columns. Initial implementation without checks and asserts Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
7d79879f66
commit
724d673fca
55
DAS/block.py
55
DAS/block.py
|
@ -51,3 +51,58 @@ class Block:
|
|||
print(line+"|")
|
||||
print(dash)
|
||||
|
||||
class SparseBlock:
|
||||
|
||||
def __init__(self, size, rows, columns):
|
||||
self.blockSize = size
|
||||
self.rows = {r: zeros(self.blockSize) for r in rows}
|
||||
self.columns = {r: zeros(self.blockSize) for r in columns}
|
||||
|
||||
def fill(self):
|
||||
for line in self.rows:
|
||||
line.setall(1)
|
||||
for line in self.columns:
|
||||
line.setall(1)
|
||||
|
||||
def merge(self, merged):
|
||||
for id in self.rows:
|
||||
self.mergeRow(id, merged.getRow(id))
|
||||
for id in self.columns:
|
||||
self.mergeColumn(id, merged.getColumn(id))
|
||||
|
||||
def getColumn(self, id):
|
||||
return self.columns[id]
|
||||
|
||||
def mergeColumn(self, id, column):
|
||||
self.columns[id] |= column
|
||||
for xid, line in self.rows.items():
|
||||
line[id] |= self.columns[id][xid]
|
||||
|
||||
def repairColumn(self, id):
|
||||
success = self.columns[id].count(1)
|
||||
if success >= self.blockSize/2:
|
||||
self.columns[id].setall(1)
|
||||
|
||||
def getRow(self, id):
|
||||
return self.rows[id]
|
||||
|
||||
def mergeRow(self, id, row):
|
||||
self.rows[id] |= row
|
||||
for xid, line in self.columns.items():
|
||||
line[id] |= self.rows[id][xid]
|
||||
|
||||
def repairRow(self, id):
|
||||
success = self.rows[id].count(1)
|
||||
if success >= self.blockSize/2:
|
||||
self.rows[id].setall(1)
|
||||
|
||||
# def print(self):
|
||||
# dash = "-" * (self.blockSize+2)
|
||||
# print(dash)
|
||||
# for i in range(self.blockSize):
|
||||
# line = "|"
|
||||
# for j in range(self.blockSize):
|
||||
# line += "%i" % self.data[(i*self.blockSize)+j]
|
||||
# print(line+"|")
|
||||
# print(dash)
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@ class Validator:
|
|||
self.ID = ID
|
||||
self.format = {"entity": "Val "+str(self.ID)}
|
||||
self.blockSize = blockSize
|
||||
self.block = Block(blockSize)
|
||||
self.receivedBlock = Block(blockSize)
|
||||
self.proposer = proposer
|
||||
self.failureRate = failureRate
|
||||
self.logger = logger
|
||||
|
@ -43,6 +41,8 @@ class Validator:
|
|||
random.seed(self.ID)
|
||||
self.rowIDs = random.sample(range(self.blockSize), self.chi)
|
||||
self.columnIDs = random.sample(range(self.blockSize), self.chi)
|
||||
self.block = SparseBlock(blockSize, self.rowIDs, self.columnIDs)
|
||||
self.receivedBlock = SparseBlock(blockSize, self.rowIDs, self.columnIDs)
|
||||
self.rowNeighbors = collections.defaultdict(list)
|
||||
self.columnNeighbors = collections.defaultdict(list)
|
||||
|
||||
|
|
Loading…
Reference in New Issue