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

a static vector of bits compressed to its entropy, with rank and select More...

#include <ADS/succinct/RRRBitVector.h>

Public member functions

 RRRBitVector (void)
 the vector of no bit
 RRRBitVector (const BitVector &b)
 the bits of \( b \), compressed
std::size_t size (void) const
 the number of bits, \( m \)
std::size_t ones (void) const
 the number of 1s
std::size_t zeros (void) const
 the number of 0s
bool operator[] (std::size_t i) const
 the bit \( i \), i.e., whether the rank changes past it within its block
std::size_t rank1 (std::size_t i) const
 the number of 1s in the places \( [ 0 , i ) \)
std::size_t rank0 (std::size_t i) const
 the number of 0s in the places \( [ 0 , i ) \), i.e., \( i - \mathrm{rank}_1( i ) \)
std::size_t select1 (std::size_t k) const
 the place of the \( k \)-th 1
std::size_t select0 (std::size_t k) const
 the place of the \( k \)-th 0, as select1() above with the 0s of each block counted as its length less its class, and the block rebuilt whole when it is sparse in 0s
std::size_t sizeInBits (void) const
 the bits of the classes, of the offsets and of the superblocks
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 parameters of the layout of the blocks, in a file

Static public attributes

static constexpr std::string_view persistName = "RRRBitVector"
 the name of the structure in a file [see Persistence.h]

Detailed description

a static vector of bits compressed to its entropy, with rank and select

Constructor and destructor documentation

◆ RRRBitVector() [1/2]

ADS::RRRBitVector::RRRBitVector ( void )
inline

the vector of no bit

◆ RRRBitVector() [2/2]

ADS::RRRBitVector::RRRBitVector ( const BitVector & b)
explicit

the bits of \( b \), compressed

In pseudocode (Raman, Raman and Rao, beyond the book), \( C \) the classes, \( O \) the offsets, \( R \) and \( P \) the 1s and the place of the first offset of each superblock:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( B ) \cr 2 & \quad n \gets 0 \cr 3 & \quad \textbf{foreach}\ \text{block } j \text{ of } 63 \text{ bits } x \text{ of } B\ \textbf{do} \cr 4 & \qquad \textbf{if}\ j \bmod 32 = 0\ \textbf{then} \ \mathrm{append}( R , n );\ \mathrm{append}( P , | O | ) \cr 5 & \qquad c \gets \mathrm{popcount}( x );\ \mathrm{append}( C , c ) \cr 6 & \qquad o \gets \sum_{t=1}^{c} \binom{p_t}{t}\quad \triangleright \ p_1 < \cdots < p_c \text{ the places of the 1s of } x \cr 7 & \qquad \mathrm{append}( O , o \text{ in } \lceil \log_2 \binom{63}{c} \rceil \text{ bits} );\ n \gets n + c \cr 8 & \quad \mathrm{append}( R , n );\ \mathrm{append}( P , | O | ) \end{array}} \]

Member function documentation

◆ ones()

std::size_t ADS::RRRBitVector::ones ( void ) const
inlinenodiscard

the number of 1s

◆ operator[]()

bool ADS::RRRBitVector::operator[] ( std::size_t i) const
nodiscard

the bit \( i \), i.e., whether the rank changes past it within its block

Precondition
\( i < \) size()

◆ persist()

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

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

◆ persistTag()

constexpr std::uint64_t ADS::RRRBitVector::persistTag ( void )
inlinestaticnodiscardconstexpr

the parameters of the layout of the blocks, in a file

◆ rank0()

std::size_t ADS::RRRBitVector::rank0 ( std::size_t i) const
inlinenodiscard

the number of 0s in the places \( [ 0 , i ) \), i.e., \( i - \mathrm{rank}_1( i ) \)

Precondition
\( i \le \) size()

◆ rank1()

std::size_t ADS::RRRBitVector::rank1 ( std::size_t i) const
nodiscard

the number of 1s in the places \( [ 0 , i ) \)

In pseudocode (Raman, Raman and Rao, beyond the book), the block \( j \) of \( i \) located from the counts of its superblock \( s \), and its 1s from the place \( i \bmod 63 \) up rebuilt from its offset:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rank1}( i ) \cr 2 & \quad j \gets \lfloor i / 63 \rfloor;\ s \gets \lfloor j / 32 \rfloor;\ r \gets R[ s ];\ q \gets P[ s ] \cr 3 & \quad \textbf{for}\ h \gets 32 s\ \textbf{to}\ j - 1\ \textbf{do}\ r \gets r + C[ h ];\ q \gets q + \lceil \log_2 \binom{63}{C[ h ]} \rceil \cr 4 & \quad c \gets C[ j ];\ o \gets \text{the offset at the place } q \text{ of } O;\ t \gets c \cr 5 & \quad \textbf{for}\ p \gets 62\ \textbf{downto}\ i \bmod 63 \ \textbf{while}\ t > 0\ \textbf{do} \cr 6 & \qquad \textbf{if}\ \binom{p}{t} \le o\ \textbf{then}\ o \gets o - \binom{p}{t};\ t \gets t - 1 \cr 7 & \quad \textbf{return}\ r + t\quad \triangleright\ t \text{ the 1s } \text{below the place } i \bmod 63 \end{array}} \]

Precondition
\( i \le \) size()

◆ select0()

std::size_t ADS::RRRBitVector::select0 ( std::size_t k) const
nodiscard

the place of the \( k \)-th 0, as select1() above with the 0s of each block counted as its length less its class, and the block rebuilt whole when it is sparse in 0s

Precondition
\( 1 \le k \le \) zeros()
Postcondition
the bit there is 0 and rank0() of it is \( k - 1 \)

◆ select1()

std::size_t ADS::RRRBitVector::select1 ( std::size_t k) const
nodiscard

the place of the \( k \)-th 1

In pseudocode (Raman, Raman and Rao, beyond the book), the names as in rank1() above:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{select1}( k ) \cr 2 & \quad s \gets \text{the last superblock with } R[ s ] < k \text{, by} \text{ a binary search} \cr 3 & \quad r \gets k - R[ s ];\ q \gets P[ s ];\ j \gets 32 s \cr 4 & \quad \textbf{while}\ r > C[ j ]\ \textbf{do}\ r \gets r - C[ j ]; \ q \gets q + \lceil \log_2 \binom{63}{C[ j ]} \rceil;\ j \gets j + 1 \cr 5 & \quad o \gets \text{the offset at the place } q \text{ of } O;\ t \gets C[ j ] \cr 6 & \quad \textbf{for}\ p \gets 62\ \textbf{downto}\ 0\ \textbf{do} \cr 7 & \qquad \textbf{if}\ \binom{p}{t} \le o\ \textbf{then} \cr 8 & \qquad\quad \textbf{if}\ t = r\ \textbf{then return}\ 63 j + p \cr 9 & \qquad\quad o \gets o - \binom{p}{t};\ t \gets t - 1 \end{array}} \]

Precondition
\( 1 \le k \le \) ones()
Postcondition
the bit there is 1 and rank1() of it is \( k - 1 \)

◆ size()

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

the number of bits, \( m \)

◆ sizeInBits()

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

the bits of the classes, of the offsets and of the superblocks

◆ zeros()

std::size_t ADS::RRRBitVector::zeros ( void ) const
inlinenodiscard

the number of 0s

Member data documentation

◆ persistName

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

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


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