* @return Longest common prefix array
*/
protected static int[] calculateLongestCommonPrefixes(Suffixes suffixes) {
int length = suffixes.size();
Corpus corpus = suffixes.getCorpus();
int[] longestCommonPrefixes = new int[length +1];
// For each element in the suffix array
for (int i = 1; i < length; i++) {
int corpusIndex = suffixes.getCorpusIndex(i);
int prevCorpusIndex = suffixes.getCorpusIndex(i-1);
// Start by assuming that the two positions
// don't have anything in common
int commonPrefixSize = 0;
// While the 1st position is not at the end of the corpus...
while(corpusIndex+commonPrefixSize < length &&
// ... and the 2nd position is not at the end of the corpus...
prevCorpusIndex + commonPrefixSize < length &&
// ... and the nth word at the 1st position ...
(corpus.getWordID(corpusIndex + commonPrefixSize) ==
// ... is the same as the nth word at the 2nd position ...
corpus.getWordID(prevCorpusIndex + commonPrefixSize) &&
// ... and the length to consider isn't too long
commonPrefixSize <= Suffixes.MAX_COMPARISON_LENGTH)) {
// The two positions match for their respective nth words!
// Increment commonPrefixSize to reflect this fact