public class SuffixArray extends Object
This implementation uses a nested class Suffix to represent
a suffix of a string (using constant time and space) and
Arrays.sort() to sort the array of suffixes.
For alternate implementations of the same API, see
SuffixArrayX, which is faster in practice (uses 3-way radix quicksort)
and uses less memory (does not create Suffix objects).
The index and length operations takes constant time
in the worst case. The lcp operation takes time proportional to the
length of the longest common prefix.
The select operation takes time proportional
to the length of the suffix and should be used primarily for debugging.
For additional documentation, see Section 6.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
SuffixArray(String text)
Initializes a suffix array for the given text string.
|
| Modifier and Type | Method and Description |
|---|---|
int |
index(int i)
Returns the index into the original string of the ith smallest suffix.
|
int |
lcp(int i)
Returns the length of the longest common prefix of the ith
smallest suffix and the i-1st smallest suffix.
|
int |
length()
Returns the length of the input string.
|
static void |
main(String[] args)
Unit tests the SuffixArray data type.
|
int |
rank(String query)
Returns the number of suffixes strictly less than the query string.
|
String |
select(int i)
Returns the ith smallest suffix as a string.
|
public SuffixArray(String text)
text - the input stringpublic int length()
public int index(int i)
i - an integer between 0 and N-1IndexOutOfBoundsException - unless 0 ≤ i < Npublic int lcp(int i)
i - an integer between 1 and N-1IndexOutOfBoundsException - unless 1 ≤ i < Npublic String select(int i)
i - the indexIndexOutOfBoundsException - unless 0 ≤ i < Npublic int rank(String query)
query - the query stringpublic static void main(String[] args)
Copyright © 2014. All Rights Reserved.