the suffix array of a text with its \( \mathit{LCP} \), \( \mathit{Llcp} \) and \( \mathit{Rlcp} \) arrays and the range minima of \( \mathit{LCP} \)
More...
|
| | SuffixArray (void)=default |
| | the index of the empty text
|
| | SuffixArray (std::string_view T) |
| | the index of the bytes of \( T \), built by suffixArraySais() and lcpArray()
|
| | SuffixArray (Symbols T, std::size_t K) |
| | the index of an integer text, built as the one of the bytes above
|
| std::pair< std::size_t, std::size_t > | range (const Symbols &P, long *comparisons=nullptr) const |
| | the range \( [ \mathit{first} , \mathit{last} ) \) of \( \mathit{SA} \) of the suffixes prefixed by \( P \), by two binary searches; the comparisons of symbols go to *comparisons, if given
|
| std::pair< std::size_t, std::size_t > | range (std::string_view P, long *comparisons=nullptr) const |
| | the range of range() above, of the bytes of \( P \)
|
| std::pair< std::size_t, std::size_t > | rangeLcp (const Symbols &P, long *comparisons=nullptr) const |
| | the range of range() by the search of Manber and Myers, \( O( p + \log n ) \) comparisons of symbols
|
| std::pair< std::size_t, std::size_t > | rangeLcp (std::string_view P, long *comparisons=nullptr) const |
| | the range of rangeLcp() above, of the bytes of \( P \)
|
| std::size_t | count (std::string_view P) const |
| | the number of occurrences of \( P \), the size of the range of rangeLcp()
|
| std::vector< std::size_t > | locate (std::string_view P) const |
| | the places of the occurrences of \( P \), in the order of \( \mathit{SA} \): the entries of the range of rangeLcp()
|
| std::vector< std::size_t > | locate (const Symbols &P) const |
| | the places of locate() above, of an integer pattern
|
| std::size_t | lce (std::size_t i, std::size_t j) const |
| | the length of the longest common prefix of the suffixes \( i \) and \( j \), \( O( 1 ) \)
|
| std::size_t | rank (std::size_t i) const |
| | the rank of the suffix \( i \) in \( \mathit{SA} \)
|
| std::size_t | operator[] (std::size_t r) const |
| | the place \( \mathit{SA}[ r ] \) of the suffix of rank \( r \)
|
| std::size_t | size (void) const |
| | the length \( n \) of the text
|
| const Symbols & | text (void) const |
| | the text \( T \)
|
| const std::vector< std::size_t > & | lcp (void) const |
| | the array \( \mathit{LCP} \), \( n - 1 \) entries
|
| const_iterator | begin (void) const |
| | the first entry of \( \mathit{SA} \)
|
| const_iterator | end (void) const |
| | one past the last entry of \( \mathit{SA} \)
|
| const_iterator | cbegin (void) const |
| | the first entry of \( \mathit{SA} \)
|
| const_iterator | cend (void) const |
| | one past the last entry of \( \mathit{SA} \)
|
the suffix array of a text with its \( \mathit{LCP} \), \( \mathit{Llcp} \) and \( \mathit{Rlcp} \) arrays and the range minima of \( \mathit{LCP} \)
| ADS::SuffixArray::SuffixArray |
( |
std::string_view | T | ) |
|
|
explicit |
the index of the bytes of \( T \), built by suffixArraySais() and lcpArray()
In pseudocode (the search of Manber and Myers, beyond the book), the arrays \( \mathit{Llcp} \) and \( \mathit{Rlcp} \) filled by the call \( \mathrm{build}( -1 , n ) \), which gives the lcp of the suffixes at the ends of the range \( ( L , R ) \) of a binary search:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{build}( L , R ) \cr
2 & \quad \textbf{if}\ R - L = 1\ \textbf{then return}\ \mathit{LCP}[ L
] \text{ if } L \ge 0 \text{ and } R < n \text{, and 0 otherwise} \cr
3 & \quad M \gets \lfloor ( L + R ) / 2 \rfloor \cr
4 & \quad \mathit{Llcp}[ M ] \gets \mathrm{build}( L , M );
\ \mathit{Rlcp}[ M ] \gets \mathrm{build}( M , R ) \cr
5 & \quad \textbf{return}\ \min\{ \mathit{Llcp}[ M ] , \mathit{Rlcp}[ M ]
\}
\end{array}}
\]
| std::size_t ADS::SuffixArray::lce |
( |
std::size_t | i, |
|
|
std::size_t | j ) const |
|
nodiscard |
the length of the longest common prefix of the suffixes \( i \) and \( j \), \( O( 1 ) \)
In pseudocode (beyond the book), by a query of range minimum on \( \mathit{LCP} \), \( R \) the inverse of \( \mathit{SA} \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lce}( i , j ) \cr
2 & \quad \textbf{if}\ i = n\ \textbf{or}\ j = n\ \textbf{then return}
\ 0 \cr
3 & \quad \textbf{if}\ i = j\ \textbf{then return}\ n - i \cr
4 & \quad a \gets \min\{ R[ i ] , R[ j ] \};\ b \gets \max\{ R[ i ] ,
R[ j ] \} \cr
5 & \quad \textbf{return}\ \min_{a \le r < b} \mathit{LCP}[ r ]
\end{array}}
\]
- Precondition
- \( i \le n \) and \( j \le n \), \( n \) the value of size()
| std::pair< std::size_t, std::size_t > ADS::SuffixArray::range |
( |
const Symbols & | P, |
|
|
long * | comparisons = nullptr ) const |
|
nodiscard |
the range \( [ \mathit{first} , \mathit{last} ) \) of \( \mathit{SA} \) of the suffixes prefixed by \( P \), by two binary searches; the comparisons of symbols go to *comparisons, if given
In pseudocode (chapter 10, Searching Strings by Substring, of Ferragina's book, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{range}( P ) \cr
2 & \quad \textbf{return}\ ( \mathrm{bound}( P , \textbf{false} ) ,
\mathrm{bound}( P , \textbf{true} ) ) \cr
3 & \textbf{function}\ \mathrm{bound}( P , \mathit{upper} ) \cr
4 & \quad L \gets 0;\ R \gets n \cr
5 & \quad \textbf{while}\ L < R\ \textbf{do} \cr
6 & \qquad M \gets \lfloor ( L + R ) / 2 \rfloor \cr
7 & \qquad \textbf{if}\ P \text{, followed by a symbol larger than all }
\text{if } \mathit{upper} \text{, is greater than the suffix }
\mathit{SA}[ M ]\ \textbf{then} \cr
8 & \qquad\quad L \gets M + 1 \cr
9 & \qquad \textbf{else}\ R \gets M \cr
10 & \quad \textbf{return}\ L
\end{array}}
\]
| std::pair< std::size_t, std::size_t > ADS::SuffixArray::rangeLcp |
( |
const Symbols & | P, |
|
|
long * | comparisons = nullptr ) const |
|
nodiscard |
the range of range() by the search of Manber and Myers, \( O( p + \log n ) \) comparisons of symbols
In pseudocode (the search of Manber and Myers, beyond the book), the virtual ranks \( -1 \) and \( n \) at the ends, \( P \) greater than the suffix of rank \( L \) and sharing \( l \) symbols with it, not greater than the suffix of rank \( R \) and sharing \( r \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{boundLcp}( P , \mathit{upper} ) \cr
2 & \quad L \gets -1;\ R \gets n;\ l \gets 0;\ r \gets 0 \cr
3 & \quad \textbf{while}\ R - L > 1\ \textbf{do} \cr
4 & \qquad M \gets \lfloor ( L + R ) / 2 \rfloor \cr
5 & \qquad \textbf{if}\ l \ge r\ \textbf{then} \cr
6 & \qquad\quad \textbf{if}\ \mathit{Llcp}[ M ] > l\ \textbf{then}\ ( h ,
g ) \gets ( l , \textbf{true} ) \cr
7 & \qquad\quad \textbf{else if}\ \mathit{Llcp}[ M ] < l\ \textbf{then}
\ ( h , g ) \gets ( \mathit{Llcp}[ M ] , \textbf{false} ) \cr
8 & \qquad\quad \textbf{else}\ ( h , g ) \gets \text{the lcp of } P
\text{ and the suffix } \mathit{SA}[ M ] \text{, compared from } l
\text{,} \cr
& \qquad\qquad \text{and whether } P \text{ is greater} \cr
9 & \qquad \textbf{else}\ \text{the same with } r \text{, }
\mathit{Rlcp}[ M ] \text{ and the two outcomes swapped} \cr
10 & \qquad \textbf{if}\ g\ \textbf{then}\ L \gets M;\ l \gets h
\ \textbf{else}\ R \gets M;\ r \gets h \cr
11 & \quad \textbf{return}\ R
\end{array}}
\]
- Postcondition
- the range of range( P ) (an audit)