ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::FMIndex Class Reference

the FM-index of a text: its transform with the counts for the rank every \( b \) places and the places of the suffixes at the multiples of \( \mu \) More...

#include <ADS/compression/FMIndex.h>

Public member functions

 FMIndex (void)
 the index of the empty text
 FMIndex (std::string_view s, std::size_t b=64, std::size_t mu=32)
 the index of \( s \)
std::size_t size (void) const
 the length \( n \) of the text
BWT transform (void) const
 the transform of the text
std::size_t rank (char c, std::size_t k) const
 the occurrences of \( c \) in \( L[ 0 , k ) \), the \( \$ \) excluded
std::pair< std::size_t, std::size_t > range (std::string_view P) const
 the range \( [ \mathit{first} , \mathit{last} ) \) of the rows of \( M' \) prefixed by \( P \), empty if none, by backward search
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: \( L \), the counts, the marks with their directory, the samples and the arrays of the alphabet
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 = "FMIndex"
 the name of the structure in a file [see Persistence.h]

Detailed description

the FM-index of a text: its transform with the counts for the rank every \( b \) places and the places of the suffixes at the multiples of \( \mu \)

Constructor and destructor documentation

◆ FMIndex() [1/2]

ADS::FMIndex::FMIndex ( void )
inline

the index of the empty text

◆ FMIndex() [2/2]

ADS::FMIndex::FMIndex ( std::string_view s,
std::size_t b = 64,
std::size_t mu = 32 )
explicit

the index of \( s \)

In pseudocode (the FM-index of Ferragina and Manzini, beyond the book), \( \sigma \) the number of the distinct symbols of \( s \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{FMIndex}( s , b , \mu ) \cr 2 & \quad \mathit{SA} \gets \text{the suffix array of } s\$;\ L[ i ] \gets s[ \mathit{SA}[ i ] - 1 ] \text{ for each row } i \cr 3 & \quad C[ c ] \gets 1 + \text{the number of the symbols of } s \text{ } \text{smaller than } c \text{, for each } c \cr 4 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ n + 1\ \textbf{do} \cr 5 & \qquad \textbf{if}\ i \bmod b = 0\ \textbf{then}\ \mathit{occ}[ i / b ] \gets \text{the occurrences of each symbol in } L[ 0 , i ) \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
b > 0, mu > 0, \( |s| < 2^{32} \)

Member function documentation

◆ count()

std::size_t ADS::FMIndex::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()

std::string ADS::FMIndex::extract ( std::size_t i,
std::size_t j ) const
nodiscard

the substring \( s[ i , j ) \)

In pseudocode (the FM-index of Ferragina and Manzini, beyond the book), from the row of the first sampled suffix at or after \( j \), each step of the LF-mapping reading the symbol before the current suffix:

\[\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 \textbf{if}\ t - 1 < j\ \textbf{then}\ s[ t - 1 ] \gets L[ r ] \cr 6 & \qquad r \gets \mathrm{lf}( r ) \cr 7 & \quad \textbf{return}\ s[ i , j ) \end{array}} \]

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

◆ locate()

std::vector< std::size_t > ADS::FMIndex::locate ( std::string_view P) const
nodiscard

the places of the occurrences of \( P \), in increasing order

In pseudocode (the FM-index of Ferragina and Manzini, beyond the book), each row walked back by the LF-mapping to a marked one, fewer than \( \mu \) steps away:

\[\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}\ r \gets \mathrm{lf}( r );\ t \gets t + 1 \cr 6 & \qquad R \gets R \cup \{ \mathit{place}[ \mathrm{rank}_1( r ) ] + t \} \cr 7 & \quad \textbf{return}\ R \text{ sorted} \end{array}} \]

Precondition
\( P \) is not empty

◆ persist()

template<class A>
void ADS::FMIndex::persist ( A & a)

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

◆ range()

std::pair< std::size_t, std::size_t > ADS::FMIndex::range ( std::string_view P) const
nodiscard

the range \( [ \mathit{first} , \mathit{last} ) \) of the rows of \( M' \) prefixed by \( P \), empty if none, by backward search

In pseudocode (the backward search of Ferragina and Manzini, beyond the book), each step prepending the symbol \( P[ i ] \) to the suffix of \( P \) already matched:

\[\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 \textbf{if}\ \mathit{first} \ge \mathit{last}\ \textbf{then return}\ \text{an empty range} \cr 5 & \qquad c \gets P[ i ] \cr 6 & \qquad \mathit{first} \gets C[ c ] + \mathrm{rank}( c , \mathit{first} );\ \mathit{last} \gets C[ c ] + \mathrm{rank}( c , \mathit{last} ) \cr 7 & \quad \textbf{return}\ [ \mathit{first} , \mathit{last} ) \end{array}} \]

Precondition
\( P \) is not empty

◆ rank()

std::size_t ADS::FMIndex::rank ( char c,
std::size_t k ) const
nodiscard

the occurrences of \( c \) in \( L[ 0 , k ) \), the \( \$ \) excluded

In pseudocode (the FM-index of Ferragina and Manzini, beyond the book), the count stored at the start of the block of \( k \) and a scan of the rest, 8 symbols at a time in the code:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rank}( c , k ) \cr 2 & \quad \textbf{if}\ c \text{ is not in } s\ \textbf{then return}\ 0 \cr 3 & \quad a \gets \lfloor k / b \rfloor b;\ r \gets \mathit{occ}[ a / b ][ c ] \cr 4 & \quad \textbf{for}\ i \gets a\ \textbf{to}\ k - 1\ \textbf{do} \cr 5 & \qquad \textbf{if}\ L[ i ] = c \text{ and } i \text{ is not the row } \text{of the } \$\ \textbf{then}\ r \gets r + 1 \cr 6 & \quad \textbf{return}\ r \end{array}} \]

Precondition
\( k \le n + 1 \)

◆ size()

std::size_t ADS::FMIndex::size ( void ) const
inlinenodiscard

the length \( n \) of the text

◆ sizeInBits()

std::size_t ADS::FMIndex::sizeInBits ( void ) const
nodiscard

the bits of the index: \( L \), the counts, the marks with their directory, the samples and the arrays of the alphabet

◆ transform()

BWT ADS::FMIndex::transform ( void ) const
nodiscard

the transform of the text

Member data documentation

◆ persistName

std::string_view ADS::FMIndex::persistName = "FMIndex"
staticconstexpr

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


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