Skip to content

perf: Switch to using ids for hashing and eq check. #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions aiger/aig.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def children(self):
pass


@attr.frozen(cache_hash=True)
@attr.frozen(auto_detect=True)
class AndGate(Node):
left: Node
right: Node
Expand All @@ -59,15 +59,27 @@ class AndGate(Node):
def children(self):
return (self.left, self.right)

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

@attr.frozen
def __hash__(self) -> int:
return hash(id(self))


@attr.frozen(auto_detect=True)
class Inverter(Node):
input: Node

@property
def children(self):
return (self.input, )

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

def __hash__(self) -> int:
return hash(id(self))


@attr.frozen
class Input(Node):
Expand All @@ -77,6 +89,12 @@ class Input(Node):
def children(self):
return ()

def __eq__(self, other) -> bool:
return isinstance(other, Input) and (self.name == other.name)

def __hash__(self) -> int:
return hash(("input", self.name))


@attr.frozen
class LatchIn(Node):
Expand All @@ -86,6 +104,12 @@ class LatchIn(Node):
def children(self):
return ()

def __eq__(self, other) -> bool:
return isinstance(other, LatchIn) and (self.name == other.name)

def __hash__(self) -> int:
return hash(("latch", self.name))


@attr.frozen
class ConstFalse(Node):
Expand Down
18 changes: 16 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "py-aiger"
readme="README.md"
version = "6.2.3"
version = "7.0.0"
repository = "https://github.com/mvcisback/py-aiger"
description = "A python library for manipulating sequential and-inverter gates."
authors = ["Marcell Vazquez-Chanlatte <[email protected]>"]
Expand All @@ -25,6 +25,9 @@ pytest-xdist = "^3"
py-aiger-ptltl = "^3.1.0"
parsimonious = "^0.10"

[tool.poetry.group.dev.dependencies]
pytest-timeout = "^2.3.1"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Loading