Commit c2acc2b
committed
fix: Boyer-Moore bad character shift was dead code in for-loop
The bad_character_heuristic() method used a for-loop with an
assignment to the loop variable i, which was immediately
overwritten by the next iteration. This caused the algorithm
to degrade from O(n/m) to O(n*m) naive search.
Changed to a while-loop so the shift actually takes effect.
Added max(i+1, shift) guard to prevent backward skips when
the mismatched character appears to the right of the mismatch
in the pattern. Added edge case doctests.1 parent 6c04620 commit c2acc2b
1 file changed
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
86 | 98 | | |
87 | 99 | | |
88 | 100 | | |
89 | | - | |
| 101 | + | |
| 102 | + | |
90 | 103 | | |
91 | 104 | | |
92 | 105 | | |
| 106 | + | |
93 | 107 | | |
94 | 108 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 109 | + | |
98 | 110 | | |
99 | 111 | | |
100 | 112 | | |
| |||
0 commit comments