This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class last_occurrence(object): | |
"""Last occurrence functor.""" | |
def __init__(self, pattern, alphabet): | |
"""Generate a dictionary with the last occurrence of each alphabet | |
letter inside the pattern. | |
Note: This function uses str.rfind, which already is a pattern | |
matching algorithm. There are more 'basic' ways to generate this | |
dictionary.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def turbo_bmh(string, pattern): | |
""" | |
Bad character heuristic, good suffix heuristic, turbo-shift heuristic implemented on Python | |
""" | |
def _suffices_preprocessing(suffix): | |
suffix[m - 1] = m | |
g = m - 1 | |
for i in range(m - 2, -1, -1): | |
if i > g and suffix[i + m - f - 1] < i - g: |