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

a static vector of bits with rank and select in 3.125% of its bits more for the rank and less than 0.8% for each select More...

#include <ADS/succinct/CompactRankSelect.h>

Public types

using value_type = bool
 the type of an item
using size_type = std::size_t
 the type of a size
using difference_type = std::ptrdiff_t
 the type of the distance of two places
using reference = bool
 an item, returned by value
using const_reference = bool
 an item, returned by value
using const_iterator = SubscriptIterator< CompactRankSelect , bool >
 the constant iterator, random access
using iterator = const_iterator
 the same as const_iterator

Public member functions

 CompactRankSelect (void)
 the directory of no bit
 CompactRankSelect (BitVector b)
 the directory of the bits \( b \), which it keeps
 CompactRankSelect (std::span< const Word > w, std::size_t n)
 the directory of the \( n \) bits of the words \( w \), copied as they are counted
template<Executor E>
 CompactRankSelect (E &ex, BitVector b)
 the directory of CompactRankSelect( b ) above, the same entries and samples, built on the threads of the executor ex (see Parallel construction)
template<Executor E>
 CompactRankSelect (E &ex, std::span< const Word > w, std::size_t n)
 the directory of CompactRankSelect( w , n ) above, the words copied by the chunks that count them, on the threads of ex
const BitVector & bits (void) const
 the bits
std::size_t size (void) const
 the number of bits, \( m \)
bool operator[] (std::size_t i) const
 the bit \( i \)
std::size_t ones (void) const
 the number of 1s
std::size_t zeros (void) const
 the number of 0s
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, by the select of select1() above on the complemented words
std::size_t directoryBits (void) const
 the bits of the directory, beyond those of the vector
const_iterator begin (void) const
 the iterator on the first item
const_iterator end (void) const
 the iterator past the last item
const_iterator cbegin (void) const
 the same as begin()
const_iterator cend (void) const
 the same as end()
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 directory, in a file

Static public attributes

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

Detailed description

a static vector of bits with rank and select in 3.125% of its bits more for the rank and less than 0.8% for each select

Member typedef documentation

◆ const_iterator

the constant iterator, random access

◆ const_reference

an item, returned by value

◆ difference_type

the type of the distance of two places

◆ iterator

◆ reference

an item, returned by value

◆ size_type

using ADS::CompactRankSelect::size_type = std::size_t

the type of a size

◆ value_type

the type of an item

Constructor and destructor documentation

◆ CompactRankSelect() [1/5]

ADS::CompactRankSelect::CompactRankSelect ( void )
inline

the directory of no bit

◆ CompactRankSelect() [2/5]

ADS::CompactRankSelect::CompactRankSelect ( BitVector b)
explicit

the directory of the bits \( b \), which it keeps

◆ CompactRankSelect() [3/5]

ADS::CompactRankSelect::CompactRankSelect ( std::span< const Word > w,
std::size_t n )

the directory of the \( n \) bits of the words \( w \), copied as they are counted

Precondition
w.size() \( \ge \lceil n / 64 \rceil \)

◆ CompactRankSelect() [4/5]

template<Executor E>
ADS::CompactRankSelect::CompactRankSelect ( E & ex,
BitVector b )

the directory of CompactRankSelect( b ) above, the same entries and samples, built on the threads of the executor ex (see Parallel construction)

In pseudocode (the counts of the chunks, their prefix sums and the entries and samples of each chunk from its prefix, beyond the book), the superblocks cut into chunks \( C_0 , \ldots , C_{q-1} \), those of a top region never in two chunks:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{directory}( \mathit{ex} , W ) \cr 2 & \quad \textbf{foreach}\ \text{chunk } C_k\ \textbf{do in parallel} \ a_k \gets \text{the 1s of the words of } C_k \cr 3 & \quad c_0 \gets 0;\ c_{k + 1} \gets c_k + a_k \text{ for } k = 0 , \ldots , q - 2 \cr 4 & \quad \textbf{foreach}\ \text{chunk } C_k\ \textbf{do in parallel} \cr 5 & \qquad \text{the entries of its superblocks from } c = c_k \text{, and its samples from the } \lceil c_k / 4096 \rceil \text{-th} \cr 6 & \quad \text{the closing samples, as in } \mathrm{directory}( W ) \end{array}} \]

◆ CompactRankSelect() [5/5]

template<Executor E>
ADS::CompactRankSelect::CompactRankSelect ( E & ex,
std::span< const Word > w,
std::size_t n )

the directory of CompactRankSelect( w , n ) above, the words copied by the chunks that count them, on the threads of ex

Precondition
w.size() \( \ge \lceil n / 64 \rceil \)

Member function documentation

◆ begin()

const_iterator ADS::CompactRankSelect::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ bits()

const BitVector & ADS::CompactRankSelect::bits ( void ) const
inlinenodiscard

the bits

◆ cbegin()

const_iterator ADS::CompactRankSelect::cbegin ( void ) const
inlinenodiscard

the same as begin()

◆ cend()

const_iterator ADS::CompactRankSelect::cend ( void ) const
inlinenodiscard

the same as end()

◆ directoryBits()

std::size_t ADS::CompactRankSelect::directoryBits ( void ) const
nodiscard

the bits of the directory, beyond those of the vector

◆ end()

const_iterator ADS::CompactRankSelect::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ ones()

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

the number of 1s

◆ operator[]()

bool ADS::CompactRankSelect::operator[] ( std::size_t i) const
inlinenodiscard

the bit \( i \)

Precondition
\( i < \) size()

◆ persist()

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

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

◆ persistTag()

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

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

◆ rank0()

std::size_t ADS::CompactRankSelect::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::CompactRankSelect::rank1 ( std::size_t i) const
nodiscard

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

In pseudocode (the flat rank of Kurpicz, beyond the book), \( T \) the counts of the top regions, \( S \) and \( c \) those of the entries and \( w_0 , \ldots , w_7 \) the words of the block of \( i \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rank1}( i ) \cr 2 & \quad r \gets T[ \lfloor i / 2^{32} \rfloor ] + S[ \lfloor i / 4096 \rfloor ] + c_{\lfloor i / 512 \rfloor \bmod 8} \cr 3 & \quad o \gets i \bmod 512 \cr 4 & \quad \textbf{for}\ j \gets 0\ \textbf{to}\ 7\ \textbf{do}\quad \triangleright\ \text{with no branch} \cr 5 & \qquad r \gets r + \mathrm{popcount}( w_j \bmod 2^{\min( 64 , \max( 0 , o - 64 j ) )} ) \cr 6 & \quad \textbf{return}\ r \end{array}} \]

Precondition
\( i \le \) size()

◆ select0()

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

the place of the \( k \)-th 0, by the select of select1() above on the complemented words

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

◆ select1()

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

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

In pseudocode (the select of Kurpicz, beyond the book), for the bits \( b = 1 \) (the words complemented for the 0s), \( Z \) the superblocks of the samples and \( \mathrm{before}( s ) \) the bits \( b \) before the superblock \( s \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{select}( k ) \cr 2 & \quad j \gets \lfloor ( k - 1 ) / 4096 \rfloor \cr 3 & \quad s \gets \text{the last superblock in } [ Z[ j ] , Z[ j + 1 ] ] \text{ with } \mathrm{before}( s ) < k\text{, by a binary search} \cr 4 & \quad r \gets k - \mathrm{before}( s ) \cr 5 & \quad q \gets \text{the last block } h \text{ of } s \text{ with } c_h < r;\ r \gets r - c_q \cr 6 & \quad p \gets \text{the last word } h \text{ of the block with } \sum_{h' < h} \mathrm{popcount}( w_{h'} ) < r \cr 7 & \quad r \gets r - \sum_{h' < p} \mathrm{popcount}( w_{h'} ) \cr 8 & \quad \textbf{return}\ \text{the place of } w_p + \mathrm{selectInWord}( w_p , r - 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::CompactRankSelect::size ( void ) const
inlinenodiscard

the number of bits, \( m \)

◆ zeros()

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

the number of 0s

Member data documentation

◆ persistName

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

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


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