Skip to content

Instantly share code, notes, and snippets.

@justinvanwinkle
Created December 19, 2013 03:06
Show Gist options
  • Save justinvanwinkle/8033733 to your computer and use it in GitHub Desktop.
Save justinvanwinkle/8033733 to your computer and use it in GitHub Desktop.
for(i = 0; i < BUCKET_A_SIZE; ++i) { bucket_A[i] = 0; }
for(i = 0; i < BUCKET_B_SIZE; ++i) { bucket_B[i] = 0; }
/* Count the number of occurrences of the first one or two characters of each
type A, B and B* suffix. Moreover, store the beginning position of all
type B* suffixes into the array SA. */
for(i = n - 1, m = n, c0 = T[n - 1]; 0 <= i;) {
/* type A suffix. */
do { ++BUCKET_A(c1 = c0); } while((0 <= --i) && ((c0 = T[i]) >= c1));
if(0 <= i) {
/* type B* suffix. */
++BUCKET_BSTAR(c0, c1);
SA[--m] = i;
/* type B suffix. */
for(--i, c1 = c0; (0 <= i) && ((c0 = T[i]) <= c1); --i, c1 = c0) {
++BUCKET_B(c0, c1);
}
}
}
m = n - m;
for i in range(len(bucket_A)):
bucket_A[i] = 0
for i in range(len(bucket_B)):
bucket_B[i] = 0
i = n - 1
while i >= 0:
i = n - 1
m = n
c0 = T[n - 1]
while i >= 0 and c0 > c1:
c1 = c0
bucket_A[c1] += 1
while i >= 0 and c0 >= c1:
c1 = c0
bucket_A[c1] += 1
i -= 1
c0 = T[i]
i -= 1
c1 = c0
if i >= 0:
bucket_B[fix_addr(c1, c0, self._alphabet_size)] += 1;
m -= 1
SA[m] = i
while i >= 0 and c0 <= c1:
i -= 1
c1 = c0
bucket_B[fix_addr(c0, c1, self._alphabet_size)] += 1
m = n - m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment