Commit b877176d authored by Vladimír Štill's avatar Vladimír Štill
Browse files

lib: Add slots to CFG data structures

parent c9d312df
Pipeline #79989 passed with stage
in 1 minute and 34 seconds
......@@ -111,6 +111,8 @@ def zip_fill(seqa: Iterable[TA], seqb: Iterable[TB], sentinel: bool = False) \
class ChangeTracker:
__slots__ = ["_changed"]
def __init__(self):
self._changed = True
......@@ -135,6 +137,8 @@ class CFG:
Word = Tuple[Terminal, ...]
Rules = Dict[Nonterminal, Set[Production]]
__slots__ = ["nonterminals", "terminals", "rules", "init"]
def __init__(self, nonterminals: Set[Nonterminal],
terminals: Set[Terminal],
rules: CFG.Rules,
......@@ -651,6 +655,8 @@ class WordGenerator:
CountMap = Dict[Nonterminal, int]
ProdCountMap = Dict[CFG.Production, int]
__slots__ = ["cfg", "_seen", "_stack", "_cur_lenght", "_next_length", "last", "counts", "prod_counts"]
def __init__(self, cfg: CFG):
self.cfg = cfg.proper()
self._seen: Set[CFG.Symbols] = set()
......@@ -832,6 +838,9 @@ class WordGenerator:
class CachedCYK:
__slots__ = ["cfg", "cache"]
def __init__(self, cfg: CFG):
self.cfg = cfg.cnf()
self.cache: Dict[CFG.Word, Set[Nonterminal]] = dict()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment