We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 468dcb5 commit 8f627e5Copy full SHA for 8f627e5
algorithms/searching/bmh_search.py
@@ -30,7 +30,14 @@ def search(text, pattern):
30
offsets = []
31
if pattern_length > text_length:
32
return offsets
33
+ # bmbc is a lookup-tuple of "skip values"
34
+ # if we're looking at an index of text, and we
35
+ # can't find part of pattern there, we can safely
36
+ # skip back up to pattern_length characters
37
bmbc = [pattern_length] * 256
38
+ # if we do find part of pattern there, but it's a
39
+ # failed search at that index, we jump back
40
+ # (pattern_length - k - 1) characters
41
for k, p in enumerate(pattern[:-1]):
42
bmbc[ord(p)] = pattern_length - k - 1
43
bmbc = tuple(bmbc)
0 commit comments