From 9ab51278c880ed52473e257cb5b6089d72d4258d Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 14 Feb 2023 11:45:55 +0100 Subject: [PATCH] add shuffledDict helper Signed-off-by: Csaba Kiraly --- DAS/validator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/DAS/validator.py b/DAS/validator.py index 67ef141..311205d 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -15,6 +15,12 @@ def shuffled(lis): for index in random.sample(range(len(lis)), len(lis)): yield lis[index] +def shuffledDict(d): + lis = list(d.values()) + # based on https://stackoverflow.com/a/60342323 + for index in random.sample(range(len(d)), len(d)): + yield lis[index] + def sampleLine(line, limit): """ sample up to 'limit' bits from a bitarray @@ -233,7 +239,7 @@ class Validator: line = self.getColumn(columnID) if line.any(): self.logger.debug("col %d -> %s", columnID, self.columnNeighbors[columnID] , extra=self.format) - for n in shuffled(list(self.columnNeighbors[columnID].values())): + for n in shuffledDict(self.columnNeighbors[columnID]): # if there is anything new to send, send it toSend = line & ~n.sent & ~n.received @@ -245,7 +251,7 @@ class Validator: line = self.getRow(rowID) if line.any(): self.logger.debug("row %d -> %s", rowID, self.rowNeighbors[rowID], extra=self.format) - for n in shuffled(list(self.rowNeighbors[rowID].values())): + for n in shuffledDict(self.rowNeighbors[rowID]): # if there is anything new to send, send it toSend = line & ~n.sent & ~n.received