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...
|
| | 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()
|
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
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}}
\]
template<bool Lazy>
template<Executor E>
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}}
\]
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()
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 \)