@@ -99,19 +99,14 @@ def __init__(self, reference: RegexTree, min_len: int, max_len: int | None, prec
99
99
self .current : dict [str , list [str ]
100
100
] = self ._calculate () if not self .done else {}
101
101
102
- def update (self ) :
102
+ def update_reference (self , new_strings : set [ str ]) -> None :
103
103
if self ._max_len is not None and self ._min_len + self ._index >= self ._max_len and self .reference .done :
104
104
self .done = True
105
105
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 )]
115
110
116
111
def _calculate (self ) -> dict [str , set [str ]]:
117
112
current_ref = self .reference .current
@@ -121,10 +116,8 @@ def _calculate(self) -> dict[str, set[str]]:
121
116
result : dict [str , list [str ]] = {}
122
117
123
118
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 )]
128
121
129
122
return result
130
123
@@ -324,8 +317,8 @@ def next(self) -> set[str]:
324
317
return result
325
318
326
319
for reference in self .references :
327
- reference .update ( )
328
- return self . current
320
+ reference .update_reference ( result )
321
+ return result
329
322
330
323
def _calculate (self ) -> set [str ]:
331
324
assert self ._index_repetition != 0
0 commit comments