Skip to content

Commit 2ddf97e

Browse files
authored
Modify suffix array algorithm to use K-based sorting
Refactor suffix array construction to use a base K for sorting.
1 parent 97d50cf commit 2ddf97e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/strings/suffix_array/suffix_array_short.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
//! @time O(n * log^2(n))
1212
//! @space O(n)
1313
auto sa_short(const auto& s) {
14+
const int K = 4;
1415
int n = sz(s);
1516
vi sa(n), sa_inv(all(s)), lcp(n - 1);
1617
iota(all(sa), 0);
17-
for (int k = 1; k <= n; k *= 2) {
18+
for (int j = 1; j <= n; j *= K) {
1819
vi x(sa_inv);
1920
auto proj = [&](int i) {
20-
return pair(x[i], i + k < n ? x[i + k] : -1);
21+
array<int, K> res;
22+
rep (k, 0, K)
23+
res[k] = i + j * k < n ? x[i + j * k] : -1;
24+
return res;
25+
//return pair(x[i], i + j < n ? x[i + j] : -1);
2126
};
2227
ranges::sort(sa, {}, proj);
2328
sa_inv[sa[0]] = 0;

0 commit comments

Comments
 (0)