Skip to content

Commit cb838a3

Browse files
mvcisbackmasinag
andcommitted
perf: Switch to using ids for hashing and eq check.
closes: #135 BREAKING_CHANGE: Structually equal circuits will not necessarily be equal now. co-authored-by: Gabriele Masina <[email protected]>
1 parent f501715 commit cb838a3

File tree

6 files changed

+6324
-15
lines changed

6 files changed

+6324
-15
lines changed

aiger/aig.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def children(self):
5050
pass
5151

5252

53-
@attr.frozen(cache_hash=True)
53+
@attr.frozen(auto_detect=True)
5454
class AndGate(Node):
5555
left: Node
5656
right: Node
@@ -59,15 +59,27 @@ class AndGate(Node):
5959
def children(self):
6060
return (self.left, self.right)
6161

62+
def __eq__(self, other) -> bool:
63+
return id(self) == id(other) # Allow for duplication.
6264

63-
@attr.frozen
65+
def __hash__(self) -> int:
66+
return hash(id(self))
67+
68+
69+
@attr.frozen(auto_detect=True)
6470
class Inverter(Node):
6571
input: Node
6672

6773
@property
6874
def children(self):
6975
return (self.input, )
7076

77+
def __eq__(self, other) -> bool:
78+
return id(self) == id(other) # Allow for duplication.
79+
80+
def __hash__(self) -> int:
81+
return hash(id(self))
82+
7183

7284
@attr.frozen
7385
class Input(Node):
@@ -77,6 +89,12 @@ class Input(Node):
7789
def children(self):
7890
return ()
7991

92+
def __eq__(self, other) -> bool:
93+
return isinstance(other, Input) and (self.name == other.name)
94+
95+
def __hash__(self) -> int:
96+
return hash(("input", self.name))
97+
8098

8199
@attr.frozen
82100
class LatchIn(Node):
@@ -86,6 +104,12 @@ class LatchIn(Node):
86104
def children(self):
87105
return ()
88106

107+
def __eq__(self, other) -> bool:
108+
return isinstance(other, LatchIn) and (self.name == other.name)
109+
110+
def __hash__(self) -> int:
111+
return hash(("latch", self.name))
112+
89113

90114
@attr.frozen
91115
class ConstFalse(Node):

poetry.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "py-aiger"
33
readme="README.md"
4-
version = "6.2.3"
4+
version = "7.0.0"
55
repository = "https://github.com/mvcisback/py-aiger"
66
description = "A python library for manipulating sequential and-inverter gates."
77
authors = ["Marcell Vazquez-Chanlatte <[email protected]>"]
@@ -25,6 +25,9 @@ pytest-xdist = "^3"
2525
py-aiger-ptltl = "^3.1.0"
2626
parsimonious = "^0.10"
2727

28+
[tool.poetry.group.dev.dependencies]
29+
pytest-timeout = "^2.3.1"
30+
2831
[build-system]
2932
requires = ["poetry>=0.12"]
3033
build-backend = "poetry.masonry.api"

0 commit comments

Comments
 (0)