Skip to content

Commit

Permalink
Fix undefined behavior in Suffix Array (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssk4988 authored Sep 19, 2024
1 parent 33ef8eb commit 57c9289
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/strings/SuffixArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ struct SuffixArray {
vi sa, lcp;
SuffixArray(string& s, int lim=256) { // or basic_string<int>
int n = sz(s) + 1, k = 0, a, b;
vi x(all(s)+1), y(n), ws(max(n, lim)), rank(n);
sa = lcp = y, iota(all(sa), 0);
vi x(all(s)), y(n), ws(max(n, lim)), rank(n);
x.push_back(0), sa = lcp = y, iota(all(sa), 0);
for (int j = 0, p = 0; p < n; j = max(1, j * 2), lim = p) {
p = j, iota(all(y), n - j);
rep(i,0,n) if (sa[i] >= j) y[p++] = sa[i] - j;
Expand Down

0 comments on commit 57c9289

Please sign in to comment.