Skip to content

Commit

Permalink
Allow vector<int> in SuffixArray
Browse files Browse the repository at this point in the history
Ref #264.
  • Loading branch information
simonlindholm committed Jan 25, 2025
1 parent 8d63451 commit 7515986
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions content/strings/SuffixArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
* The \texttt{lcp} array contains longest common prefixes for
* neighbouring strings in the suffix array:
* \texttt{lcp[i] = lcp(sa[i], sa[i-1])}, \texttt{lcp[0] = 0}.
* The input string must not contain any zero bytes.
* The input string must not contain any nul chars.
* Time: O(n \log n)
* Status: stress-tested
*/
#pragma once

struct SuffixArray {
vi sa, lcp;
SuffixArray(string& s, int lim=256) { // or basic_string<int>
int n = sz(s) + 1, k = 0, a, b;
SuffixArray(string s, int lim=256) { // or vector<int>
s.push_back(0); int n = sz(s), k = 0, a, b;
vi x(all(s)), y(n), ws(max(n, lim));
x.push_back(0), sa = lcp = y, iota(all(sa), 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 7515986

Please sign in to comment.