Skip to content

Commit 38e6ee1

Browse files
committed
cached hash of NGram
1 parent a934699 commit 38e6ee1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

synth/syntax/grammars/grammar.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ class NGram:
1313
n: int
1414
predecessors: List[Tuple[DerivableProgram, int]] = field(default_factory=lambda: [])
1515

16+
_hash: "int | None" = field(init=False)
17+
18+
def __post_init__(self):
19+
object.__setattr__(self, "_hash", hash((self.n, tuple(self.predecessors))))
20+
1621
def __hash__(self) -> int:
17-
return hash((self.n, tuple(self.predecessors)))
22+
return self._hash
1823

1924
def __str__(self) -> str:
2025
return str(self.predecessors)

0 commit comments

Comments
 (0)