|
ADS
Algorithms and Data Structures
|
the r-index of a text: count and locate in space proportional to the runs of its transform More...
#include <ADS/compression/RIndex.h>
Public member functions | |
| RIndex (void) | |
| the index of the empty text | |
| RIndex (std::string_view s) | |
| the index of \( s \) | |
| std::size_t | size (void) const |
| the length \( n \) of the text | |
| std::size_t | runs (void) const |
| the number \( r \) of the runs of the transform | |
| std::pair< std::size_t, std::size_t > | range (std::string_view P) const |
| the range \( [ \mathit{first} , \mathit{last} ) \) of the rows prefixed by \( P \), empty if none | |
| std::size_t | count (std::string_view P) const |
| the number of the occurrences of \( P \) | |
| std::vector< std::size_t > | locate (std::string_view P) const |
| the places of the occurrences of \( P \), in increasing order | |
| std::size_t | sizeInBits (void) const |
| the bits of the index: the runs, their heads, the sums of their lengths, the samples and the function \( \phi \) | |
| template<class A> | |
| void | persist (A &a) |
| the members written to, or read from, the archive \( a \) [see Persistence.h] | |
Static public attributes | |
| static constexpr std::string_view | persistName = "RIndex" |
| the name of the structure in a file [see Persistence.h] | |
the r-index of a text: count and locate in space proportional to the runs of its transform
|
inline |
the index of the empty text
|
explicit |
the index of \( s \)
In pseudocode (the r-index of Gagie, Navarro and Prezza, beyond the book), with the runs of \( L \) numbered \( 0 , \ldots , r - 1 \), the run \( j \) from \( p_j \) to \( e_j \) with the head \( h_j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{RIndex}( s ) \cr 2 & \quad \mathit{SA} \gets \text{the suffix array of } s\$;\ L[ i ] \gets s[ \mathit{SA}[ i ] - 1 ] + 1 \text{, 0 for the } \$ \cr 3 & \quad \text{split } L \text{ in its maximal runs;}\ \text{store the } \text{starts } p_j \text{ in Elias-Fano} \cr 4 & \quad \text{store the heads } h_j \text{ in a wavelet tree of } \text{Huffman} \cr 5 & \quad C[ c ] \gets \text{the symbols of } L \text{ below } c;\ R_c \gets \text{the runs of the symbols below } c \cr 6 & \quad \textbf{for}\ j \gets 0\ \textbf{to}\ r - 1\ \textbf{do}\quad \triangleright\ \text{the starts in } F \cr 7 & \qquad c \gets h_j;\ k \gets \text{the number of the runs of } c \text{ before } j \cr 8 & \qquad F_{R_c + k} \gets C[ c ] + \text{the length of these runs} \cr 9 & \quad \textbf{for}\ j \gets 0\ \textbf{to}\ r - 1\ \textbf{do} \ \mathit{end}[ j ] \gets \mathit{SA}[ e_j ] \cr 10 & \quad \mathit{key} \gets \text{the values } \mathit{SA}[ p_j ] \text{ for } j \ge 1 \text{, sorted, in Elias-Fano} \cr 11 & \quad \mathit{run}[ k ] \gets \text{the } j \text{ of } \mathit{key}[ k ] \text{, for each } k \end{array}} \]
|
nodiscard |
the number of the occurrences of \( P \)
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{count}( P ) \cr 2 & \quad [ \mathit{first} , \mathit{last} ) \gets \mathrm{range}( P ); \ \textbf{return}\ \mathit{last} - \mathit{first} \end{array}} \]
|
nodiscard |
the places of the occurrences of \( P \), in increasing order
In pseudocode (the toehold and the function \( \phi \) of Gagie, Navarro and Prezza, beyond the book), \( v \) the place of the suffix of the last row of the range:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{locate}( P ) \cr 2 & \quad \mathit{first} \gets 0;\ \mathit{last} \gets n + 1;\ v \gets \mathit{end}[ r - 1 ] \cr 3 & \quad \textbf{for}\ i \gets p - 1\ \textbf{downto}\ 0\ \textbf{do} \cr 4 & \qquad c \gets P[ i ] + 1;\ j \gets \text{the run of } \mathit{last} - 1 \cr 5 & \qquad \textbf{if}\ h_j = c\ \textbf{then}\ v \gets v - 1 \cr 6 & \qquad \textbf{else if}\ \text{a run of } c \text{ comes before } j \ \textbf{then} \cr 7 & \qquad\quad v \gets \mathit{end}[ \text{the last such run} ] - 1 \cr 8 & \qquad \mathit{first} \gets C[ c ] + \mathrm{rank}_c( \mathit{first} );\ \mathit{last} \gets C[ c ] + \mathrm{rank}_c( \mathit{last} ) \cr 9 & \qquad \textbf{if}\ \mathit{first} \ge \mathit{last}\ \textbf{then return}\ \emptyset \cr 10 & \quad R \gets \{ v \} \cr 11 & \quad \textbf{for}\ k \gets \mathit{first} + 1\ \textbf{to} \ \mathit{last} - 1\ \textbf{do}\ v \gets \phi( v );\ R \gets R \cup \{ v \} \cr 12 & \quad \textbf{return}\ R \text{ sorted} \cr 13 & \textbf{function}\ \phi( x ) \cr 14 & \quad k \gets \text{the place of the largest } \mathit{key} \le x \cr 15 & \quad \textbf{return}\ \mathit{end}[ \mathit{run}[ k ] - 1 ] + x - \mathit{key}[ k ] \end{array}} \]
| void ADS::RIndex::persist | ( | A & | a | ) |
the members written to, or read from, the archive \( a \) [see Persistence.h]
|
nodiscard |
the range \( [ \mathit{first} , \mathit{last} ) \) of the rows prefixed by \( P \), empty if none
In pseudocode (the backward search of the r-index, beyond the book), the rank on the runs of the description of the header:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{range}( P ) \cr 2 & \quad \mathit{first} \gets 0;\ \mathit{last} \gets n + 1 \cr 3 & \quad \textbf{for}\ i \gets p - 1\ \textbf{downto}\ 0\ \textbf{do} \cr 4 & \qquad c \gets P[ i ] + 1 \cr 5 & \qquad \mathit{first} \gets C[ c ] + \mathrm{rank}_c( \mathit{first} );\ \mathit{last} \gets C[ c ] + \mathrm{rank}_c( \mathit{last} ) \cr 6 & \qquad \textbf{if}\ \mathit{first} \ge \mathit{last}\ \textbf{then return}\ \text{an empty range} \cr 7 & \quad \textbf{return}\ [ \mathit{first} , \mathit{last} ) \cr 8 & \textbf{function}\ \mathrm{rank}_c( i ) \cr 9 & \quad \textbf{if}\ i = 0\ \textbf{then return}\ 0 \cr 10 & \quad j \gets \text{the run of } i - 1;\ k \gets \text{the runs of } c \text{ before } j \cr 11 & \quad x \gets F_{R_c + k} - C[ c ] \cr 12 & \quad \textbf{if}\ h_j = c\ \textbf{then}\ x \gets x + i - p_j \cr 13 & \quad \textbf{return}\ x \end{array}} \]
|
inlinenodiscard |
the number \( r \) of the runs of the transform
|
inlinenodiscard |
the length \( n \) of the text
|
nodiscard |
the bits of the index: the runs, their heads, the sums of their lengths, the samples and the function \( \phi \)
|
staticconstexpr |
the name of the structure in a file [see Persistence.h]