public class SuffixArrayX extends Object
This implementation uses 3-way radix quicksort to sort the array of suffixes.
For a simpler (but less efficient) implementations of the same API, see
SuffixArray.
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 |
|---|
SuffixArrayX(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 SuffixArrayx 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 SuffixArrayX(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.