We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3929a02 commit fca604cCopy full SHA for fca604c
pydatastructs/strings/algorithms.py
@@ -90,20 +90,19 @@ def bitap_search(text, pattern):
90
Returns the starting index of the pattern in the text, or -1 if not found.
91
"""
92
m = len(pattern)
93
- R = ~1 # Bit array for tracking matches
+ R = ~1
94
pattern_mask = {}
95
96
- # Preprocess the pattern into a bitmask
97
for i in range(m):
98
pattern_mask[pattern[i]] = pattern_mask.get(pattern[i], ~0) & ~(1 << i)
99
100
for i in range(len(text)):
101
R |= pattern_mask.get(text[i], ~0)
102
R <<= 1
103
if (R & (1 << m)) == 0:
104
- return i - m + 1 # Match found
+ return i - m + 1
105
106
- return -1 # No match found
+ return -1
107
108
def _knuth_morris_pratt(text, query):
109
if len(text) == 0 or len(query) == 0:
0 commit comments