Example #1
0
def naive_all(text, n):
    p = prefix.period(text, n)
    out = []
    for i in range(1, n + 2):
        w = local_period_naive(text[1:i], text[i:])
        if len(w) == p:
            out.append((i, prefix.period(text[0] + text[i:], n + 1 - i)))
    return out
Example #2
0
def boyer_moore_shift(w, m):
    BM = [prefix.period(w, m)] + [m] * m
    S, j = maximum_suffixes(w, m), 0
    for k in range(m - 1, -1, -1):
        if k == S[k]:
            while j < m - k:
                BM[j] = m - k
                j += 1
    for k in range(1, m):
        BM[m - S[k]] = m - k
    return BM
def naive(text, n):
    out = 1
    for i in range(2, n + 1):
        if text[out:] < text[i:]:
            out = i
    return out, prefix.period(text[0] + text[out:], n + 1 - out)
def from_suffix_array(SA, t, n):
  index = SA[-1]
  return index, prefix.period('#' + t[index:], n - index + 1)