@@ -99,19 +99,14 @@ def __init__(self, reference: RegexTree, min_len: int, max_len: int | None, prec
9999 self .current : dict [str , list [str ]
100100 ] = self ._calculate () if not self .done else {}
101101
102- def update (self ) :
102+ def update_reference (self , new_strings : set [ str ]) -> None :
103103 if self ._max_len is not None and self ._min_len + self ._index >= self ._max_len and self .reference .done :
104104 self .done = True
105105
106- for string in self .reference .current :
107- if string in self .current :
108- self .current [string ].append (
109- string * (self ._min_len + self ._index ))
110- else :
111- result = []
112- for i in range (self ._min_len , self ._min_len + self ._index + 1 ):
113- result .append (string * i )
114- self .current [string ] = result
106+ for string in new_strings :
107+ assert string not in self .current
108+ self .current [string ] = [
109+ string * i for i in range (self ._min_len , self ._min_len + self ._index + 1 )]
115110
116111 def _calculate (self ) -> dict [str , set [str ]]:
117112 current_ref = self .reference .current
@@ -121,10 +116,8 @@ def _calculate(self) -> dict[str, set[str]]:
121116 result : dict [str , list [str ]] = {}
122117
123118 for string in current_ref :
124- partial = []
125- for i in range (self ._min_len , self ._min_len + self ._index + 1 ):
126- partial .append (string * i )
127- result [string ] = partial
119+ result [string ] = [
120+ string * i for i in range (self ._min_len , self ._min_len + self ._index + 1 )]
128121
129122 return result
130123
@@ -324,8 +317,8 @@ def next(self) -> set[str]:
324317 return result
325318
326319 for reference in self .references :
327- reference .update ( )
328- return self . current
320+ reference .update_reference ( result )
321+ return result
329322
330323 def _calculate (self ) -> set [str ]:
331324 assert self ._index_repetition != 0
0 commit comments