Skip to content

Commit 8f627e5

Browse files
committed
added description of the key feature of BMH search: the "OccTable"
1 parent 468dcb5 commit 8f627e5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

algorithms/searching/bmh_search.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ def search(text, pattern):
3030
offsets = []
3131
if pattern_length > text_length:
3232
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
3337
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
3441
for k, p in enumerate(pattern[:-1]):
3542
bmbc[ord(p)] = pattern_length - k - 1
3643
bmbc = tuple(bmbc)

0 commit comments

Comments
 (0)