a vector of bits packed in words of 64 bits
More...
#include <ADS/succinct/BitVector.h>
|
| | BitVector (void)=default |
| | the empty vector
|
| | BitVector (std::size_t n, bool b=false) |
| | \( n \) bits equal to \( b \)
|
| | BitVector (std::string_view s) |
| | the bits written in \( s \), the bit 0 first
|
| | BitVector (std::span< const Word > w, std::size_t n) |
| | the \( n \) bits of the words \( w \), the bit \( i \) in the bit \( i \bmod 64 \) of the word \( \lfloor i / 64 \rfloor \), as in words()
|
| std::size_t | size (void) const |
| | the number of bits
|
| bool | empty (void) const |
| | whether there is no bit
|
| bool | operator[] (std::size_t i) const |
| | the bit \( i \)
|
| void | set (std::size_t i, bool b=true) |
| | writes \( b \) in the bit \( i \)
|
| void | push_back (bool b) |
| | appends the bit \( b \)
|
| void | append (Word v, int len) |
| | appends the \( \mathit{len} \) bits of \( v \), its bit 0 first
|
| Word | get (std::size_t i, int len) const |
| | the \( \mathit{len} \) bits from the place \( i \), the bit \( i \) in the bit 0 of the result
|
| void | put (std::size_t i, Word v, int len) |
| | writes the \( \mathit{len} \) bits of \( v \) from the place \( i \), its bit 0 in the bit \( i \)
|
| std::size_t | count (void) const |
| | the number of 1 bits, in \( O( n / 64 ) \) time
|
| const Words & | words (void) const |
| | the words, the bits past the size being 0; they are at least \( \lfloor n / 64 \rfloor + 2 \), a multiple of 8, and start on a line of the cache
|
| std::string | toString (void) const |
| | the bits as a string of '0' and '1', the bit 0 first
|
| void | reserve (std::size_t n) |
| | room for \( n \) bits
|
| void | clear (void) |
| | no bit
|
| template<class A> |
| void | persist (A &a) |
| | the members written to, or read from, the archive \( a \) [see Persistence.h]: the size and the words, a view of a mapped file if \( a \) reads one
|
| 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()
|
a vector of bits packed in words of 64 bits
◆ 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
◆ value_type
◆ BitVector() [1/4]
| ADS::BitVector::BitVector |
( |
void | | ) |
|
|
default |
◆ BitVector() [2/4]
| ADS::BitVector::BitVector |
( |
std::size_t | n, |
|
|
bool | b = false ) |
|
explicit |
\( n \) bits equal to \( b \)
◆ BitVector() [3/4]
| ADS::BitVector::BitVector |
( |
std::string_view | s | ) |
|
|
explicit |
the bits written in \( s \), the bit 0 first
- Precondition
- \( s \) has only the characters '0' and '1'
◆ BitVector() [4/4]
| ADS::BitVector::BitVector |
( |
std::span< const Word > | w, |
|
|
std::size_t | n ) |
the \( n \) bits of the words \( w \), the bit \( i \) in the bit \( i \bmod 64 \) of the word \( \lfloor i / 64 \rfloor \), as in words()
- Precondition
- \( w \) holds \( \lceil n / 64 \rceil \) words at least
◆ append()
| void ADS::BitVector::append |
( |
Word | v, |
|
|
int | len ) |
appends the \( \mathit{len} \) bits of \( v \), its bit 0 first
In pseudocode (beyond the book), \( n \) the size and \( W \) the words, which grow by a line when the last one is reached:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{append}( v , \mathit{len} ) \cr
2 & \quad w \gets \lfloor n / 64 \rfloor;\ o \gets n \bmod 64 \cr
3 & \quad W[ w ] \gets W[ w ] \vee ( v \ll o )\quad \triangleright
\ \text{the bits past } n \text{ are } 0 \cr
4 & \quad \textbf{if}\ o + \mathit{len} > 64\ \textbf{then}\ W[ w + 1 ]
\gets v \gg ( 64 - o ) \cr
5 & \quad n \gets n + \mathit{len}
\end{array}}
\]
- Precondition
- \( \mathit{len} \le 64 \) and \( v < 2^{\mathit{len}} \)
- Postcondition
- get( size() - len , len ) is \( v \)
◆ begin()
the iterator on the first item
◆ cbegin()
◆ cend()
◆ clear()
| void ADS::BitVector::clear |
( |
void | | ) |
|
◆ count()
| std::size_t ADS::BitVector::count |
( |
void | | ) |
const |
|
nodiscard |
the number of 1 bits, in \( O( n / 64 ) \) time
◆ empty()
| bool ADS::BitVector::empty |
( |
void | | ) |
const |
|
nodiscard |
◆ end()
the iterator past the last item
◆ get()
| Word ADS::BitVector::get |
( |
std::size_t | i, |
|
|
int | len ) const |
|
nodiscard |
the \( \mathit{len} \) bits from the place \( i \), the bit \( i \) in the bit 0 of the result
In pseudocode (beyond the book), with no test of the end, since a word always follows the last bit:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{get}( i , \mathit{len} ) \cr
2 & \quad w \gets \lfloor i / 64 \rfloor;\ o \gets i \bmod 64 \cr
3 & \quad r \gets ( W[ w ] \gg o ) \vee ( ( W[ w + 1 ] \ll 1 ) \ll ( 63
- o ) ) \cr
4 & \quad \textbf{return}\ r \bmod 2^{\mathit{len}}
\end{array}}
\]
- Precondition
- \( \mathit{len} \le 64 \) and \( i + \mathit{len} \le \) size()
◆ operator[]()
| bool ADS::BitVector::operator[] |
( |
std::size_t | i | ) |
const |
|
nodiscard |
the bit \( i \)
- Precondition
- \( i < \) size()
◆ persist()
template<class A>
| void ADS::BitVector::persist |
( |
A & | a | ) |
|
the members written to, or read from, the archive \( a \) [see Persistence.h]: the size and the words, a view of a mapped file if \( a \) reads one
◆ push_back()
| void ADS::BitVector::push_back |
( |
bool | b | ) |
|
appends the bit \( b \)
- Postcondition
- the size grows by 1 and the last bit is \( b \)
◆ put()
| void ADS::BitVector::put |
( |
std::size_t | i, |
|
|
Word | v, |
|
|
int | len ) |
writes the \( \mathit{len} \) bits of \( v \) from the place \( i \), its bit 0 in the bit \( i \)
- Precondition
- \( \mathit{len} \le 64 \), \( v < 2^{\mathit{len}} \) and \( i + \mathit{len} \le \) size()
- Postcondition
- get( i , len ) is \( v \)
◆ reserve()
| void ADS::BitVector::reserve |
( |
std::size_t | n | ) |
|
◆ set()
| void ADS::BitVector::set |
( |
std::size_t | i, |
|
|
bool | b = true ) |
writes \( b \) in the bit \( i \)
- Precondition
- \( i < \) size()
- Postcondition
- the bit \( i \) is \( b \)
◆ size()
| std::size_t ADS::BitVector::size |
( |
void | | ) |
const |
|
nodiscard |
◆ toString()
| std::string ADS::BitVector::toString |
( |
void | | ) |
const |
|
nodiscard |
the bits as a string of '0' and '1', the bit 0 first
◆ words()
| const Words & ADS::BitVector::words |
( |
void | | ) |
const |
|
nodiscard |
the words, the bits past the size being 0; they are at least \( \lfloor n / 64 \rfloor + 2 \), a multiple of 8, and start on a line of the cache
◆ BasicRankSelect
template<bool>
| friend class BasicRankSelect |
|
friend |
◆ CompactRankSelect
| friend class CompactRankSelect |
|
friend |
◆ HuffmanWaveletTree
template<class>
| friend class HuffmanWaveletTree |
|
friend |
◆ operator==
whether the two vectors have the same bits
◆ WaveletMatrix
| friend class WaveletMatrix |
|
friend |
◆ persistName
| std::string_view ADS::BitVector::persistName = "BitVector" |
|
staticconstexpr |
The documentation for this class was generated from the following file: