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

a static vector of bits with rank and select in \( O( 1 ) \) time, the inventories of select built in the constructor if not Lazy, and at the first select of each value if Lazy More...

#include <ADS/succinct/RankSelect.h>

Inheritance diagram for ADS::BasicRankSelect< Lazy >:
ADS::RankSelectOptions

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< BasicRankSelect , bool >
 the constant iterator, random access
using iterator = const_iterator
 the same as const_iterator
Public types inherited from ADS::RankSelectOptions
enum class  Selects { NONE , ONES , ZEROS , BOTH }
 the selects that a directory answers More...

Public member functions

 BasicRankSelect (void)
 the directory of no bit
 BasicRankSelect (BitVector b, Selects s=Selects::BOTH)
 the directory of the bits \( b \), which it keeps, with the selects \( s \)
 BasicRankSelect (std::span< const Word > w, std::size_t n, Selects s=Selects::BOTH)
 the directory of the \( n \) bits of the words \( w \), copied as they are counted, with the selects \( s \)
template<Executor E>
 BasicRankSelect (E &ex, BitVector b, Selects s=Selects::BOTH)
 the directory of BasicRankSelect( b , s ) above, the same entries and inventories, built on the threads of the executor ex (see Parallel construction); if Lazy, the inventories are built by the first selects, on the calling thread
template<Executor E>
 BasicRankSelect (E &ex, std::span< const Word > w, std::size_t n, Selects s=Selects::BOTH)
 the directory of BasicRankSelect( w , n , s ) above, the words copied by the chunks that count them, on the threads of ex
 BasicRankSelect (const BasicRankSelect &o)
 a copy, with the inventories that \( o \) has built
 BasicRankSelect (BasicRankSelect &&o) noexcept
 a move, with the inventories that \( o \) has built
BasicRankSelect & operator= (const BasicRankSelect &o)
 a copy, with the inventories that \( o \) has built
BasicRankSelect & operator= (BasicRankSelect &&o) noexcept
 a move, with the inventories that \( o \) has built
 ~BasicRankSelect (void)=default
 the directory and its bits released
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, with those of the inventories of the selects asked for, built or not
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]
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()

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
 the name of the structure in a file [see Persistence.h]

Detailed description

template<bool Lazy>
class ADS::BasicRankSelect< Lazy >

a static vector of bits with rank and select in \( O( 1 ) \) time, the inventories of select built in the constructor if not Lazy, and at the first select of each value if Lazy

Member typedef documentation

◆ const_iterator

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::const_iterator = SubscriptIterator< BasicRankSelect , bool >

the constant iterator, random access

◆ const_reference

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::const_reference = bool

an item, returned by value

◆ difference_type

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::difference_type = std::ptrdiff_t

the type of the distance of two places

◆ iterator

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::iterator = const_iterator

the same as const_iterator

◆ reference

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::reference = bool

an item, returned by value

◆ size_type

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::size_type = std::size_t

the type of a size

◆ value_type

template<bool Lazy>
using ADS::BasicRankSelect< Lazy >::value_type = bool

the type of an item

Constructor and destructor documentation

◆ BasicRankSelect() [1/7]

template<bool Lazy>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( void )

the directory of no bit

◆ BasicRankSelect() [2/7]

template<bool Lazy>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( BitVector b,
Selects s = Selects::BOTH )
explicit

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

In pseudocode (the directory of Jacobson, with the blocks of 256 bits, beyond the book), \( D[ t ] \) the entry of the block \( t \) and \( W \) the words:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{directory}( W ) \cr 2 & \quad c \gets 0 \cr 3 & \quad \textbf{foreach}\ \text{block } t \text{ of four words} \ W[ 4 t .. 4 t + 3 ]\ \textbf{do} \cr 4 & \qquad p_j \gets \mathrm{popcount}( W[ 4 t + j ] )\ \text{for } j = 0 , 1 , 2 , 3 \cr 5 & \qquad r \gets ( p_0 + 2^8 p_1 + 2^{16} p_2 ) \cdot ( 1 + 2^8 + 2^{16} ) \bmod 2^{24}\quad \triangleright\ \text{the relative ranks} \cr 6 & \qquad D[ t ] \gets 2^{24} c + r;\ c \gets c + p_0 + p_1 + p_2 + p_3 \cr 7 & \quad \textbf{foreach}\ \text{value } b \text{ of the selects } s \ \textbf{do}\ \text{build the inventory of } b \text{ (if not } \mathit{Lazy} \text{)} \end{array}} \]

◆ BasicRankSelect() [3/7]

template<bool Lazy>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( std::span< const Word > w,
std::size_t n,
Selects s = Selects::BOTH )

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

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

◆ BasicRankSelect() [4/7]

template<bool Lazy>
template<Executor E>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( E & ex,
BitVector b,
Selects s = Selects::BOTH )

the directory of BasicRankSelect( b , s ) above, the same entries and inventories, built on the threads of the executor ex (see Parallel construction); if Lazy, the inventories are built by the first selects, on the calling thread

In pseudocode (the counts of the chunks, their prefix sums and the entries of each chunk from its prefix, beyond the book), the blocks cut into chunks \( C_0 , \ldots , C_{q-1} \) of consecutive blocks, those of a top block 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\quad \triangleright\ \text{the 1s before} \text{ each chunk} \cr 4 & \quad T[ j ] \gets c_k \text{ for the chunk } C_k \text{ that } \text{starts the top block } j \cr 5 & \quad \textbf{foreach}\ \text{chunk } C_k\ \textbf{do in parallel} \ \text{the entries of its blocks as in } \mathrm{directory}( W ) \text{, from } c = c_k \cr 6 & \quad \textbf{foreach}\ \text{value } b \text{ of the selects } s\ \textbf{do}\ \mathrm{inventory}( \mathit{ex} , b ) \text{ (if } \text{not } \mathit{Lazy} \text{)} \end{array}} \]

◆ BasicRankSelect() [5/7]

template<bool Lazy>
template<Executor E>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( E & ex,
std::span< const Word > w,
std::size_t n,
Selects s = Selects::BOTH )

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

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

◆ BasicRankSelect() [6/7]

template<bool Lazy>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( const BasicRankSelect< Lazy > & o)

a copy, with the inventories that \( o \) has built

◆ BasicRankSelect() [7/7]

template<bool Lazy>
ADS::BasicRankSelect< Lazy >::BasicRankSelect ( BasicRankSelect< Lazy > && o)
noexcept

a move, with the inventories that \( o \) has built

◆ ~BasicRankSelect()

template<bool Lazy>
ADS::BasicRankSelect< Lazy >::~BasicRankSelect ( void )
default

the directory and its bits released

Member function documentation

◆ begin()

template<bool Lazy>
const_iterator ADS::BasicRankSelect< Lazy >::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ bits()

template<bool Lazy>
const BitVector & ADS::BasicRankSelect< Lazy >::bits ( void ) const
nodiscard

the bits

◆ cbegin()

template<bool Lazy>
const_iterator ADS::BasicRankSelect< Lazy >::cbegin ( void ) const
inlinenodiscard

the same as begin()

◆ cend()

template<bool Lazy>
const_iterator ADS::BasicRankSelect< Lazy >::cend ( void ) const
inlinenodiscard

the same as end()

◆ directoryBits()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::directoryBits ( void ) const
nodiscard

the bits of the directory, beyond those of the vector, with those of the inventories of the selects asked for, built or not

◆ end()

template<bool Lazy>
const_iterator ADS::BasicRankSelect< Lazy >::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ ones()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::ones ( void ) const
nodiscard

the number of 1s

◆ operator=() [1/2]

template<bool Lazy>
BasicRankSelect & ADS::BasicRankSelect< Lazy >::operator= ( BasicRankSelect< Lazy > && o)
noexcept

a move, with the inventories that \( o \) has built

◆ operator=() [2/2]

template<bool Lazy>
BasicRankSelect & ADS::BasicRankSelect< Lazy >::operator= ( const BasicRankSelect< Lazy > & o)

a copy, with the inventories that \( o \) has built

◆ operator[]()

template<bool Lazy>
bool ADS::BasicRankSelect< Lazy >::operator[] ( std::size_t i) const
nodiscard

the bit \( i \)

Precondition
\( i < \) size()

◆ persist()

template<bool Lazy>
template<class A>
void ADS::BasicRankSelect< Lazy >::persist ( A & a)

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

◆ persistTag()

template<bool Lazy>
constexpr std::uint64_t ADS::BasicRankSelect< Lazy >::persistTag ( void )
inlinestaticnodiscardconstexpr

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

◆ rank0()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::rank0 ( std::size_t i) const
nodiscard

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

Precondition
\( i \le \) size()

◆ rank1()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::rank1 ( std::size_t i) const
nodiscard

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

In pseudocode (the directory of Jacobson, with the sideways sum of a word in place of the table of the small blocks, beyond the book), \( D \) the entries of the blocks of the constructor above, \( W \) the words and \( T \) the counts of the top level:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rank1}( i ) \cr 2 & \quad e \gets D[ \lfloor i / 256 \rfloor ];\ q \gets \lfloor i / 64 \rfloor \bmod 4 \cr 3 & \quad r \gets \lfloor e / 2^{24} \rfloor + \text{the count of the } \text{word } q \text{ in } e\ \text{(0 for } q = 0 \text{)} \cr 4 & \quad \textbf{if}\ m > 2^{40}\ \textbf{then}\ r \gets r + T[ \lfloor i / 2^{40} \rfloor ] \cr 5 & \quad \textbf{return}\ r + \mathrm{popcount}( W[ \lfloor i / 64 \rfloor ] \bmod 2^{i \bmod 64} ) \end{array}} \]

Precondition
\( i \le \) size()

◆ select0()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::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(), and the selects of the 0s were asked for
Postcondition
the bit there is 0 and rank0() of it is \( k - 1 \)

◆ select1()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::select1 ( std::size_t k) const
nodiscard

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

In pseudocode (the simple select of Vigna, beyond the book), for the bits \( b = 1 \) (and with the words complemented for the 0s), the group \( j \) of \( 2^\ell \) of them starting at \( P[ j ] \) and its 1s of rank multiple of \( 2^g \) at the offsets \( O \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{select}( k ) \cr 2 & \quad r \gets k - 1;\ j \gets \lfloor r / 2^\ell \rfloor \cr 3 & \quad \textbf{if}\ \text{the group } j \text{ is sparse } \ \textbf{then} \cr 4 & \qquad \textbf{return}\ \text{the place by a binary search of the } \text{blocks of } D \text{ between } P[ j ] \text{ and } P[ j + 1 ] \cr 5 & \quad p \gets P[ j ] + O[ \lfloor r / 2^g \rfloor ]\quad \triangleright\ \text{the 1 of rank } 2^g \lfloor r / 2^g \rfloor \cr 6 & \quad \textbf{if}\ g = 0\ \textbf{then return}\ p \cr 7 & \quad t \gets r \bmod 2^g;\ w \gets \lfloor p / 64 \rfloor;\ x \gets W[ w ] \text{ with the bits before } p \text{ cleared} \cr 8 & \quad \textbf{while}\ t \ge \mathrm{popcount}( x )\ \textbf{do} \ t \gets t - \mathrm{popcount}( x );\ w \gets w + 1;\ x \gets W[ w ] \cr 9 & \quad \textbf{return}\ 64 w + \mathrm{selectInWord}( x , t ) \end{array}} \]

Precondition
\( 1 \le k \le \) ones(), and the selects of the 1s were asked for
Postcondition
the bit there is 1 and rank1() of it is \( k - 1 \)

◆ size()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::size ( void ) const
nodiscard

the number of bits, \( m \)

◆ zeros()

template<bool Lazy>
std::size_t ADS::BasicRankSelect< Lazy >::zeros ( void ) const
nodiscard

the number of 0s

Member data documentation

◆ persistName

template<bool Lazy>
std::string_view ADS::BasicRankSelect< Lazy >::persistName
staticconstexpr
Initial value:
=
Lazy ? "LazyRankSelect" : "RankSelect"

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


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