ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::HuffmanFMIndex< RS > Class Template Reference

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]

Detailed description

template<class RS = RankSelect>
class ADS::HuffmanFMIndex< RS >

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 \)

Constructor and destructor documentation

◆ HuffmanFMIndex() [1/2]

template<class RS = RankSelect>
ADS::HuffmanFMIndex< RS >::HuffmanFMIndex ( void )
inline

the index of the empty text

◆ HuffmanFMIndex() [2/2]

template<class RS = RankSelect>
ADS::HuffmanFMIndex< RS >::HuffmanFMIndex ( std::string_view s,
std::size_t mu = 32 )
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}} \]

Precondition
mu > 0, \( |s| < 2^{32} \)

Member function documentation

◆ count()

template<class RS = RankSelect>
std::size_t ADS::HuffmanFMIndex< RS >::count ( std::string_view P) const
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}} \]

Precondition
\( P \) is not empty

◆ extract()

template<class RS = RankSelect>
std::string ADS::HuffmanFMIndex< RS >::extract ( std::size_t i,
std::size_t j ) const
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}} \]

Precondition
\( i \le j \le n \)

◆ locate()

template<class RS = RankSelect>
std::vector< std::size_t > ADS::HuffmanFMIndex< RS >::locate ( std::string_view P) const
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}} \]

Precondition
\( P \) is not empty

◆ persist()

template<class RS = RankSelect>
template<class A>
void ADS::HuffmanFMIndex< RS >::persist ( A & a)

the members written to, or read from, the archive \( a \) [see Persistence.h]

◆ persistTag()

template<class RS = RankSelect>
constexpr std::uint64_t ADS::HuffmanFMIndex< RS >::persistTag ( void )
inlinestaticnodiscardconstexpr

the directory of the bits, in a file

◆ range()

template<class RS = RankSelect>
std::pair< std::size_t, std::size_t > ADS::HuffmanFMIndex< RS >::range ( std::string_view P) const
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}} \]

Precondition
\( P \) is not empty

◆ size()

template<class RS = RankSelect>
std::size_t ADS::HuffmanFMIndex< RS >::size ( void ) const
inlinenodiscard

the length \( n \) of the text

◆ sizeInBits()

template<class RS = RankSelect>
std::size_t ADS::HuffmanFMIndex< RS >::sizeInBits ( void ) const
nodiscard

the bits of the index: the tree, the marks with their directory, the samples and the counts of the symbols

Member data documentation

◆ persistName

template<class RS = RankSelect>
std::string_view ADS::HuffmanFMIndex< RS >::persistName = "HuffmanFMIndex"
staticconstexpr

the name of the structure in a file [see Persistence.h]


The documentation for this class was generated from the following file: