Skip to content

Commit 54f27c5

Browse files
fix: refine pattern skipping in search functions
- Adjusted `boyer_moore_search`, `kmp_search`, `simd_search`, and `avx2_search` to increment by 1 instead of `pattern_len` - Ensured all matches are detected, preventing unintended skips - Bumped version from 0.1.1 to 0.1.2
1 parent 90bdc75 commit 54f27c5

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

krep.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* krep - A high-performance string search utility
22
*
33
* Author: Davide Santangelo
4-
* Version: 0.1.1
4+
* Version: 0.1.2
55
* Year: 2025
66
*
77
* Features:
@@ -173,7 +173,7 @@ uint64_t boyer_moore_search(const char *text, size_t text_len,
173173
}
174174
if (match) {
175175
match_count++;
176-
i += pattern_len; // changed: skip entire pattern on match
176+
i++; // Changed: increment by 1 instead of pattern_len to catch all matches
177177
} else {
178178
unsigned char bad_char = text[i];
179179
if (!case_sensitive) bad_char = tolower(bad_char);
@@ -254,9 +254,7 @@ uint64_t kmp_search(const char *text, size_t text_len,
254254

255255
if (j == pattern_len) {
256256
match_count++;
257-
// Jump ahead by one character (for single-char patterns) or full pattern
258-
// to avoid overlapping
259-
i = i - j + (pattern_len > 1 ? pattern_len : 1);
257+
i = i - j + 1;
260258
j = 0;
261259
}
262260
}
@@ -357,7 +355,7 @@ uint64_t simd_search(const char *text, size_t text_len,
357355
int um = _mm_cmpestri(up, pattern_len, lt, pattern_len, _SIDD_CMP_EQUAL_ORDERED);
358356
if (lm == 0 || um == 0) {
359357
match_count++;
360-
i += pattern_len; // Skip ahead to avoid overlapping matches
358+
i++;
361359
} else {
362360
i++;
363361
}
@@ -430,7 +428,7 @@ uint64_t avx2_search(const char *text, size_t text_len,
430428

431429
if (match) {
432430
match_count++;
433-
i += pattern_len; // Skip ahead to avoid overlapping matches
431+
i++; // Changed: increment by 1 instead of pattern_len to catch all matches
434432
} else {
435433
i++;
436434
}

0 commit comments

Comments
 (0)