Skip to content

Commit bfcd6de

Browse files
William FisetWilliam Fiset
authored andcommitted
Boyer-Moore tweak
1 parent 6d8bb42 commit bfcd6de

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/com/williamfiset/algorithms/strings/BoyerMooreStringSearch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public List<Integer> findOccurrences(String text, String pattern) {
3535

3636
int n = pattern.length();
3737
for (int textIndex = n - 1, patternIndex = n - 1; textIndex < text.length(); ) {
38+
// Found a match!
3839
if (patternIndex >= 0 && pattern.charAt(patternIndex) == text.charAt(textIndex)) {
3940
if (patternIndex == 0) {
4041
occurrences.add(textIndex);
@@ -43,7 +44,7 @@ public List<Integer> findOccurrences(String text, String pattern) {
4344
}
4445
patternIndex--;
4546
} else {
46-
textIndex += n - min(max(patternIndex, 0), 1 + skipTable[text.charAt(textIndex)]);
47+
textIndex += n - min(max(patternIndex, 0), skipTable[text.charAt(textIndex)] + 1);
4748
patternIndex = n - 1;
4849
}
4950
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy