beam: fix Aho-Corasick empty-pattern handling (emit at every position)

This commit is contained in:
beam committed 2026-10-25 14:06:35 +00:00
1 parent 51ac84210a
commit 82504de6ee
1 file changed
+5 -5
+5 -5
View File
@@ -58,14 +58,14 @@ class AhoCorasick:
for pi in self.out[node]:
plen = len(self.patterns[pi])
if plen == 0:
start = i
else:
start = i + 1 - plen
continue # handled below for every position
start = i + 1 - plen
res.append((start, pi))
# empty patterns also match at the end position
# empty patterns match at every position 0..n
for pi, p in enumerate(self.patterns):
if p == "":
res.append((n, pi))
for pos in range(n + 1):
res.append((pos, pi))
res.sort(key=lambda x: (x[0], x[1]))
return res