|
ADS
Algorithms and Data Structures
|
the r-index of a text on move structures: count and locate with each step in \( O( 1 ) \) time More...
#include <ADS/compression/MoveRIndex.h>
Public member functions | |
| MoveRIndex (void) | |
| the index of the empty text | |
| MoveRIndex (std::string_view s) | |
| the index of \( s \) | |
| std::size_t | size (void) const |
| the length \( n \) of the text | |
| std::size_t | intervals (void) const |
| the number of the intervals of the LF-mapping, after the balance | |
| 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 two move structures, the ranks of the tags and the samples | |
| 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 = "MoveRIndex" |
| the name of the structure in a file [see Persistence.h] | |
the r-index of a text on move structures: count and locate with each step in \( O( 1 ) \) time
|
inline |
the index of the empty text
|
explicit |
the index of \( s \)
In pseudocode (the move-r of Bertram, Fischer and Nalbach, beyond the book), with the runs of \( L \) from \( p_j \) with the head \( h_j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{MoveRIndex}( 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 \textbf{foreach}\ \text{run } j \text{ of } L\ \textbf{do} \ q_j \gets C[ h_j ] + \text{the } h_j \text{ in } L[ 0 , p_j ) \cr 4 & \quad \mathit{LF} \gets \text{the move structure of } p \mapsto q \text{, tagged by } h \cr 5 & \quad \mathit{tag} \gets \text{the tags of its intervals, in a } \text{wavelet tree of Huffman} \cr 6 & \quad \phi \gets \text{the move structure of } \mathit{SA}[ p_j ] \mapsto \mathit{SA}[ p_j - 1 ] \text{, cyclically} \cr 7 & \quad \textbf{foreach}\ \text{interval } i \text{ of } \mathit{LF}\ \textbf{do} \cr 8 & \qquad x \gets \mathit{SA}[ \text{the last row of } i ]; \ \mathit{end}[ i ] \gets x \cr 9 & \qquad \mathit{endPhi}[ i ] \gets \text{the interval of } \phi \text{ of } x - 1 \end{array}} \]
|
nodiscard |
the number of the occurrences of \( P \)
In pseudocode (the backward search of the move-r, beyond the book), \( \mathit{s} \) and \( \mathit{e} \) with their intervals \( i_s \) and \( i_e \), which \( \mathrm{move} \) keeps:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{count}( P ) \cr 2 & \quad ( \mathit{s} , i_s ) \gets ( 0 , 0 );\ ( \mathit{e} , i_e ) \gets ( n , \text{the last interval} ) \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 \textbf{if}\ \mathit{tag}[ i_s ] \ne c\ \textbf{then} \cr 6 & \qquad\quad i_s \gets \text{the next interval of tag } c \text{ } \text{after } i_s \text{, or } \textbf{return}\ 0 \cr 7 & \qquad\quad \mathit{s} \gets \text{the start of } i_s \cr 8 & \qquad \textbf{if}\ \mathit{tag}[ i_e ] \ne c\ \textbf{then} \cr 9 & \qquad\quad i_e \gets \text{the previous interval of tag } c \text{ } \text{before } i_e \text{, or } \textbf{return}\ 0 \cr 10 & \qquad\quad \mathit{e} \gets \text{the end of } i_e \cr 11 & \qquad \textbf{if}\ \mathit{s} > \mathit{e}\ \textbf{then return} \ 0 \cr 12 & \qquad ( \mathit{s} , i_s ) \gets \mathit{LF}.\mathrm{move}( \mathit{s} , i_s );\ ( \mathit{e} , i_e ) \gets \mathit{LF}.\mathrm{move}( \mathit{e} , i_e ) \cr 13 & \quad \textbf{return}\ \mathit{e} - \mathit{s} + 1 \end{array}} \]
|
inlinenodiscard |
the number of the intervals of the LF-mapping, after the balance
|
nodiscard |
the places of the occurrences of \( P \), in increasing order
In pseudocode (the move-r of Bertram, Fischer and Nalbach, beyond the book), the search of count() keeping the toehold \( v = \mathit{SA}[ \mathit{e} ] \) with its interval \( i_v \) of \( \phi \), and with \( i_e \) in the line 5 already moved to the previous interval of \( c \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{locate}( P ) \cr 2 & \quad v \gets \mathit{end}[ \text{the last interval} ];\ i_v \gets \text{the interval of } \phi \text{ of } v \cr 3 & \quad \text{run the search of } \mathrm{count}( P ) \text{, and at } \text{each step, before the moves:} \cr 4 & \qquad \textbf{if}\ \mathit{tag}[ i_e ] = c\ \textbf{then}\ v \gets v - 1;\ \textbf{if}\ v \text{ is before the start of } i_v \ \textbf{then}\ i_v \gets i_v - 1 \cr 5 & \qquad \textbf{else}\ v \gets \mathit{end}[ i_e ] - 1;\ i_v \gets \mathit{endPhi}[ i_e ] \cr 6 & \quad \textbf{if}\ P \text{ does not occur}\ \textbf{then return} \ \emptyset \cr 7 & \quad R \gets \{ v \} \cr 8 & \quad \textbf{for}\ k \gets \mathit{s}\ \textbf{to}\ \mathit{e} - 1 \ \textbf{do}\ ( v , i_v ) \gets \phi.\mathrm{move}( v , i_v );\ R \gets R \cup \{ v \} \cr 9 & \quad \textbf{return}\ R \text{ sorted} \end{array}} \]
| void ADS::MoveRIndex::persist | ( | A & | a | ) |
the members written to, or read from, the archive \( a \) [see Persistence.h]
|
inlinenodiscard |
the length \( n \) of the text
|
nodiscard |
the bits of the index: the two move structures, the ranks of the tags and the samples
|
staticconstexpr |
the name of the structure in a file [see Persistence.h]