Skip to content

Commit c58d2a6

Browse files
committed
Fixing bool-oblivious hashing
1 parent 7205204 commit c58d2a6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tools/bvdd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def __init__(self, i2o):
354354
self.i2o = i2o
355355

356356
def __hash__(self):
357-
return hash(tuple(self.i2o.items()))
357+
return hash((tuple(self.i2o.items()), tuple(isinstance(o, bool) for o in self.i2o.values())))
358358

359359
def __eq__(self, bvdd2):
360360
return type(bvdd2) is type(self) and self.i2o == bvdd2.i2o
@@ -447,7 +447,7 @@ def __init__(self, s2o):
447447
self.s2o = s2o
448448

449449
def __hash__(self):
450-
return hash(tuple(self.s2o.items()))
450+
return hash((tuple(self.s2o.items()), tuple(isinstance(o, bool) for o in self.s2o.values())))
451451

452452
def __eq__(self, bvdd2):
453453
return type(bvdd2) is type(self) and self.s2o == bvdd2.s2o
@@ -550,7 +550,7 @@ def __init__(self, o2s):
550550
self.o2s = o2s
551551

552552
def __hash__(self):
553-
return hash(tuple(self.o2s.items()))
553+
return hash((tuple(self.o2s.items()), tuple(isinstance(o, bool) for o in self.o2s)))
554554

555555
def __eq__(self, bvdd2):
556556
return type(bvdd2) is type(self) and self.o2s == bvdd2.o2s

tools/cflobvdd.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,9 @@ def __str__(self):
13211321
f"o: {self.outputs}\n")
13221322

13231323
def __hash__(self):
1324-
return hash((self.grouping, tuple(self.outputs.values())))
1324+
return hash((self.grouping,
1325+
tuple(self.outputs.values()),
1326+
isinstance(self.outputs[1], bool)))
13251327

13261328
def __eq__(self, n2):
13271329
return (isinstance(n2, CFLOBVDD) and

0 commit comments

Comments
 (0)