ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RIndex.h File Reference

The r-index of Gagie, Navarro and Prezza (beyond the book): the FM-index of a text \( s \) of \( n \) bytes in space proportional to the number \( r \) of the runs of its transform \( L \) of Burrows and Wheeler, rather than to \( n \) [see FMIndex.h, HuffmanFMIndex.h], so that a repetitive text (the versions of a document, the genomes of a species), where \( r \) is far smaller than \( n \), takes far less; count( P ) takes \( O( p ) \) steps of rank on the runs, and locate( P ) \( O( p + \mathit{occ} ) \) more of predecessor searches. More...

#include "ADS/Contract.h"
#include "ADS/compression/BurrowsWheeler.h"
#include "ADS/succinct/BitVector.h"
#include "ADS/succinct/EliasFano.h"
#include "ADS/succinct/HuffmanWaveletTree.h"
#include <algorithm>
#include <array>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "ADS/compression/impl/RIndex.tpp"

Go to the source code of this file.

Classes

class  ADS::RIndex
 the r-index of a text: count and locate in space proportional to the runs of its transform More...

Namespaces

namespace  ADS

Detailed description

The r-index of Gagie, Navarro and Prezza (beyond the book): the FM-index of a text \( s \) of \( n \) bytes in space proportional to the number \( r \) of the runs of its transform \( L \) of Burrows and Wheeler, rather than to \( n \) [see FMIndex.h, HuffmanFMIndex.h], so that a repetitive text (the versions of a document, the genomes of a species), where \( r \) is far smaller than \( n \), takes far less; count( P ) takes \( O( p ) \) steps of rank on the runs, and locate( P ) \( O( p + \mathit{occ} ) \) more of predecessor searches.

\( L \) is kept as its runs: the start of each run in an Elias-Fano sequence [see EliasFano.h], the symbol of each run (its head) in a wavelet tree of Huffman [see HuffmanWaveletTree.h], and the starts of the runs in the column \( F \), the runs of each symbol \( c \) after those of the symbols before it, in one more Elias-Fano sequence: the run \( k \) of \( c \) starts in \( F \) at \( C[ c ] + S_c[ k ] \), with \( S_c[ k ] \) the lengths of the first \( k \) runs of \( c \), at the place \( R_c + k \) of the sequence, with \( R_c \) the runs of the symbols below \( c \) (one sequence of \( r \) items in \( [ 0 , n ] \) rather than one for each symbol, which would cost the entropy of the heads more per run). The rank of \( c \) in \( L[ 0 , i ) \) is then

\[ \mathrm{rank}_c( i ) = F_{R_c + k} - C[ c ] + [ h_j = c ] \, ( i - p_j ) , \qquad k = \mathrm{rank}_c( h , j ) , \]

with \( j \) the run of the place \( i - 1 \), \( p_j \) its start and \( h_j \) its head (one predecessor search, and one descent of the tree for both ranks of \( c \) around \( j \)), and count( P ) is the backward search of the FM-index with it.

locate( P ) keeps, along the backward search, the place in \( s \) of the suffix of the last row of the range, \( \mathit{SA}[ e - 1 ] \) (the toehold): if \( L[ e - 1 ] = c \) the row moves by the LF-mapping and the place decreases by 1, and otherwise the last \( c \) before \( e - 1 \) ends a run of \( c \), whose place is kept (a sample of \( \mathit{SA} \) at each end of a run). The other occurrences follow from the function \( \phi( \mathit{SA}[ i ] ) = \mathit{SA}[ i - 1 ] \), which shifts every stretch between two places of the starts of the runs alike:

\[ \phi( x ) = \phi( y ) + ( x - y ) , \qquad y = \max \{ \mathit{SA}[ p_j ] : \mathit{SA}[ p_j ] \le x \} , \]

so that the places \( \mathit{SA}[ p_j ] \) of the starts of the runs, sorted, in Elias-Fano, give it by one predecessor search: \( \phi( \mathit{SA}[ p_j ] ) = \mathit{SA}[ p_j - 1 ] \) is the sample at the end of the run \( j - 1 \), and only \( j \) is kept, in \( \lceil \log_2 r \rceil \) bits. All of it takes \( O( r ) \) words: 5 sequences of \( r \) integers of \( \lceil \log_2 n \rceil \) bits or less and the heads, whose rank and select are those of CompactRankSelect [see CompactRankSelect.h], the smallest.

The symbols of \( L \) are the bytes plus 1, the end of the text being

  1. The transform comes from the suffix array of SA-IS [see BurrowsWheeler.h], in \( O( n ) \) time and words; the r-index of the literature is built in \( O( r ) \) words from the run-length transform, which this one does not attempt.

The contracts [see Contract.h]: \( n < 2^{32} \), a pattern is not empty; each place found by locate() is an occurrence, an audit against the text kept for it only at the level of the audits. The functions are defined in RIndex.tpp.

See also
T. Gagie, G. Navarro, N. Prezza, Fully functional suffix trees and optimal text searching in BWT-runs bounded space, Journal of the ACM 67(1), 2, 2020, doi:10.1145/3375890
T. Gagie, G. Navarro, N. Prezza, Optimal-time text indexing in BWT-runs bounded space, Proc. 29th SODA, 1459-1477, 2018, doi:10.1137/1.9781611975031.96
V. Mäkinen, G. Navarro, Succinct suffix arrays based on run-length encoding, Proc. 16th CPM, LNCS 3537, 45-56, 2005, doi:10.1007/11496656_5
G. Navarro, Indexing highly repetitive string collections, part II: compressed indexes, ACM Computing Surveys 54(2), 26, 2021, doi:10.1145/3432999
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa