Skip to content

Commit a637445

Browse files
authored
Improve suffix array comparison handling
Refactor comparison logic to handle -1 case in suffix array.
1 parent 4534728 commit a637445

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/strings/suffix_array/suffix_array_short.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ auto sa_short(const auto& s) {
2222
rep (k, 0, K) {
2323
int a = i1 + j * k < n ? x[i1 + j * k] : -1;
2424
int b = i2 + j * k < n ? x[i2 + j * k] : -1;
25-
if (a != b) return val += y[b], a < b;
25+
if (a != b) {
26+
if (a != -1) val += y[a];
27+
else val = n - i1;
28+
return a < b;
29+
}
2630
val += j;
2731
}
2832
return false;

0 commit comments

Comments
 (0)