|
ADS
Algorithms and Data Structures
|
The suffix array of a text \( T \) of \( n \) symbols, beyond the book: \( \mathit{SA}[ r ] \) is the starting place of the \( r \)-th smallest suffix of \( T \) in the lexicographic order, a suffix that is a prefix of another being the smaller. More...
#include "ADS/Contract.h"#include "ADS/search/RangeMinimum.h"#include "ADS/sort/RadixSort.h"#include <algorithm>#include <cstddef>#include <cstdint>#include <limits>#include <numeric>#include <string_view>#include <tuple>#include <utility>#include <vector>#include "ADS/string/impl/SuffixArray.tpp"Go to the source code of this file.
Classes | |
| class | ADS::SuffixArray |
| the suffix array of a text with its \( \mathit{LCP} \), \( \mathit{Llcp} \) and \( \mathit{Rlcp} \) arrays and the range minima of \( \mathit{LCP} \) More... | |
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::Symbols = std::vector< std::size_t > |
| a text on an integer alphabet | |
Functions | |
| Symbols | ADS::toSymbols (std::string_view T) |
| the bytes of \( T \) as symbols in \( [ 0 , 256 ) \) | |
| std::vector< std::size_t > | ADS::suffixArraySorting (const Symbols &T) |
| the suffix array of \( T \) by a sort of comparisons of its suffixes | |
| std::vector< std::size_t > | ADS::suffixArraySorting (std::string_view T) |
| the array of suffixArraySorting() above, on the bytes of \( T \) | |
| std::vector< std::size_t > | ADS::suffixArrayDoubling (const Symbols &T) |
| the suffix array of \( T \) by the prefix doubling of Manber and Myers | |
| std::vector< std::size_t > | ADS::suffixArrayDoubling (std::string_view T) |
| the array of suffixArrayDoubling() above, on the bytes of \( T \) | |
| std::vector< std::size_t > | ADS::suffixArrayLarssonSadakane (const Symbols &T) |
| the suffix array of \( T \) by the doubling of Larsson and Sadakane | |
| std::vector< std::size_t > | ADS::suffixArrayLarssonSadakane (std::string_view T) |
| the array of suffixArrayLarssonSadakane() above, on the bytes of \( T \) | |
| std::vector< std::size_t > | ADS::suffixArraySkew (const Symbols &T, std::size_t K) |
| the suffix array of \( T \) by the Skew algorithm of Kärkkäinen and Sanders | |
| std::vector< std::size_t > | ADS::suffixArraySkew (std::string_view T) |
| the array of suffixArraySkew() above, on the bytes of \( T \) | |
| std::vector< std::size_t > | ADS::suffixArraySais (const Symbols &T, std::size_t K) |
| the suffix array of \( T \) by the induced sorting of Nong, Zhang and Chan | |
| std::vector< std::size_t > | ADS::suffixArraySais (std::string_view T) |
| the array of suffixArraySais() above, on the bytes of \( T \) | |
| std::vector< std::size_t > | ADS::suffixArrayScan (const Symbols &T, std::size_t m) |
| the suffix array of \( T \) by the scan-based algorithm of Baeza-Yates, Gonnet and Snider, on blocks of \( m \) symbols | |
| std::vector< std::size_t > | ADS::suffixArrayScan (std::string_view T, std::size_t m) |
| the array of suffixArrayScan() above, on the bytes of \( T \) | |
| std::vector< std::size_t > | ADS::inversePermutation (const std::vector< std::size_t > &SA) |
| the inverse of a permutation: \( R[ \mathit{SA}[ r ] ] = r \) | |
| std::vector< std::size_t > | ADS::lcpArray (const Symbols &T, const std::vector< std::size_t > &SA) |
| the LCP array of Kasai et al., \( n - 1 \) entries (none if \( n < 2 \)) | |
| std::vector< std::size_t > | ADS::lcpArray (std::string_view T, const std::vector< std::size_t > &SA) |
| the array of lcpArray() above, on the bytes of \( T \) | |
The suffix array of a text \( T \) of \( n \) symbols, beyond the book: \( \mathit{SA}[ r ] \) is the starting place of the \( r \)-th smallest suffix of \( T \) in the lexicographic order, a suffix that is a prefix of another being the smaller.
The occurrences of a pattern \( P \) of \( p \) symbols are the suffixes prefixed by \( P \), which lie in a contiguous range of \( \mathit{SA} \), found by binary search; the array takes \( n \) integers besides \( T \), against the 10 to 20 \( n \) bytes of a suffix tree [see SuffixTree.h]. The places count from 0, and no terminator is stored: chapter 10, Searching Strings by Substring, of Ferragina's book writes \( T \) with a final \( \$ \), whose suffix would be the first of \( \mathit{SA} \).
The constructions, each giving the same array:
lcpArray() is the algorithm of Kasai, Lee, Arimura, Arikawa and Park: \( \mathit{LCP}[ r ] \) is the length of the longest common prefix of the suffixes \( \mathit{SA}[ r ] \) and \( \mathit{SA}[ r + 1 ] \), and since the suffix \( i + 1 \) shares at least \( h - 1 \) symbols with its predecessor in \( \mathit{SA} \) when the suffix \( i \) shares \( h \) with its own, the suffixes taken in the order of the text extend \( h \) without going back, \( 2 n \) comparisons of symbols in all.
SuffixArray keeps \( T \), \( \mathit{SA} \), its inverse, \( \mathit{LCP} \) and two more arrays of the lcp, \( \mathit{Llcp} \) and \( \mathit{Rlcp} \), of the suffix in the middle of each range of the binary search with the suffixes at its two ends:
A text is a std::string_view, whose symbols are its bytes, or a vector of integers in \( [ 0 , K ) \), e.g., several strings joined by separators [see SuffixApplications.h]. The doubling needs \( n < 2^{32} \), since the radix sort takes a pair of ranks as one key of 64 bits.
The contracts [see Contract.h]: the symbols of an integer text are less than \( K \); every construction gives a suffix array, checked in \( O( n ) \) by comparing each adjacent pair through the ranks of the following suffixes (an audit), and lcpArray() the lcp of each adjacent pair (an audit); the two searches give the same range. The functions are defined in SuffixArray.tpp.