|
ADS
Algorithms and Data Structures
|
the FM-index of a text on the wavelet tree of Huffman of its transform, with the places of the suffixes at the multiples of \( \mu \) More...
#include <ADS/compression/HuffmanFMIndex.h>
Public member functions | |
| HuffmanFMIndex (void) | |
| the index of the empty text | |
| HuffmanFMIndex (std::string_view s, std::size_t mu=32) | |
| the index of \( s \) | |
| std::size_t | size (void) const |
| the length \( n \) of the text | |
| 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::string | extract (std::size_t i, std::size_t j) const |
| the substring \( s[ i , j ) \) | |
| std::size_t | sizeInBits (void) const |
| the bits of the index: the tree, the marks with their directory, the samples and the counts of the symbols | |
| template<class A> | |
| void | persist (A &a) |
| the members written to, or read from, the archive \( a \) [see Persistence.h] | |
Static public member functions | |
| static constexpr std::uint64_t | persistTag (void) |
| the directory of the bits, in a file | |
Static public attributes | |
| static constexpr std::string_view | persistName = "HuffmanFMIndex" |
| the name of the structure in a file [see Persistence.h] | |
the FM-index of a text on the wavelet tree of Huffman of its transform, with the places of the suffixes at the multiples of \( \mu \)
|
inline |
the index of the empty text
|
explicit |
the index of \( s \)
In pseudocode (the succinct suffix array of Mäkinen and Navarro, beyond the book), the places and the rows of the samples in \( w = \lceil \log_2 ( n + 1 ) \rceil \) bits each:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{HuffmanFMIndex}( s , \mu ) \cr 2 & \quad \mathit{SA} \gets \text{the suffix array of } s\$ \cr 3 & \quad L[ i ] \gets s[ \mathit{SA}[ i ] - 1 ] + 1 \text{ for each row } i \text{, and } 0 \text{ for the row of the } \$ \cr 4 & \quad C[ c ] \gets \text{the number of the symbols of } L \text{ } \text{smaller than } c \text{, for each } c \cr 5 & \quad \text{build the wavelet tree of Huffman of } L \cr 6 & \quad \textbf{foreach}\ \text{row } i \text{ with } \mathit{SA}[ i ] \bmod \mu = 0\ \textbf{do} \cr 7 & \qquad \text{mark } i;\ \mathit{place}[ \mathrm{rank}_1( i ) ] \gets \mathit{SA}[ i ];\ \mathit{row}[ \mathit{SA}[ i ] / \mu ] \gets i \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 substring \( s[ i , j ) \)
In pseudocode (the succinct suffix array of Mäkinen and Navarro, beyond the book), from the row of the first sampled suffix at or after \( j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{extract}( i , j ) \cr 2 & \quad p \gets \lceil j / \mu \rceil \mu \cr 3 & \quad \textbf{if}\ p \ge n\ \textbf{then}\ p \gets n;\ r \gets 0 \ \textbf{else}\ r \gets \mathit{row}[ p / \mu ] \cr 4 & \quad \textbf{for}\ t \gets p\ \textbf{downto}\ i + 1\ \textbf{do} \quad \triangleright\ r \text{ is the row of the suffix } t \cr 5 & \qquad ( c , k ) \gets \mathrm{accessRank}( r ) \cr 6 & \qquad \textbf{if}\ t - 1 < j\ \textbf{then}\ s[ t - 1 ] \gets c - 1 \cr 7 & \qquad r \gets C[ c ] + k \cr 8 & \quad \textbf{return}\ s[ i , j ) \end{array}} \]
|
nodiscard |
the places of the occurrences of \( P \), in increasing order
In pseudocode (the succinct suffix array of Mäkinen and Navarro, beyond the book), each step of the LF-mapping one descent of the tree that gives the symbol \( c = L[ r ] \) and its rank \( k \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{locate}( P ) \cr 2 & \quad [ \mathit{first} , \mathit{last} ) \gets \mathrm{range}( P ); \ R \gets \emptyset \cr 3 & \quad \textbf{for}\ r \gets \mathit{first}\ \textbf{to} \ \mathit{last} - 1\ \textbf{do} \cr 4 & \qquad t \gets 0 \cr 5 & \qquad \textbf{while}\ r \text{ is not marked}\ \textbf{do} \cr 6 & \qquad\quad ( c , k ) \gets \mathrm{accessRank}( r );\ r \gets C[ c ] + k;\ t \gets t + 1 \cr 7 & \qquad R \gets R \cup \{ \mathit{place}[ \mathrm{rank}_1( r ) ] + t \} \cr 8 & \quad \textbf{return}\ R \text{ sorted} \end{array}} \]
the members written to, or read from, the archive \( a \) [see Persistence.h]
|
inlinestaticnodiscardconstexpr |
the directory of the bits, in a file
|
nodiscard |
the range \( [ \mathit{first} , \mathit{last} ) \) of the rows prefixed by \( P \), empty if none
In pseudocode (the backward search of Ferragina and Manzini, beyond the book), the two ranks of a step taken by one descent of the tree:
\[\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 ( a , b ) \gets ( \mathrm{rank}_c( \mathit{first} ) , \mathrm{rank}_c( \mathit{last} ) ) \text{ on the tree} \cr 6 & \qquad \mathit{first} \gets C[ c ] + a;\ \mathit{last} \gets C[ c ] + b \cr 7 & \qquad \textbf{if}\ \mathit{first} \ge \mathit{last}\ \textbf{then return}\ \text{an empty range} \cr 8 & \quad \textbf{return}\ [ \mathit{first} , \mathit{last} ) \end{array}} \]
|
inlinenodiscard |
the length \( n \) of the text
|
nodiscard |
the bits of the index: the tree, the marks with their directory, the samples and the counts of the symbols
|
staticconstexpr |
the name of the structure in a file [see Persistence.h]