a stream of bits read forward from a place of a BitVector, which must outlive the reader
More...
#include <ADS/succinct/BitStream.h>
|
| | BitReader (const BitVector &b, std::size_t p=0) |
| | the bits of \( b \) from the place \( p \)
|
| std::size_t | position (void) const |
| | the place of the next bit
|
| void | seek (std::size_t p) |
| | moves to the place \( p \)
|
| bool | atEnd (void) const |
| | whether all the bits have been read
|
| bool | readBit (void) |
| | the next bit
|
| Word | read (int len) |
| | the next \( \mathit{len} \) bits, the first in the least significant place
|
| Word | readBinary (int len) |
| | the next \( \mathit{len} \) bits, the first in the most significant place, the field of writeBinary()
|
| std::uint64_t | readUnary (void) |
| | the number of zeros before the next 1, which is read too
|
a stream of bits read forward from a place of a BitVector, which must outlive the reader
◆ BitReader()
| ADS::BitReader::BitReader |
( |
const BitVector & | b, |
|
|
std::size_t | p = 0 ) |
|
explicit |
the bits of \( b \) from the place \( p \)
- Precondition
- \( p \le \) b.size()
◆ atEnd()
| bool ADS::BitReader::atEnd |
( |
void | | ) |
const |
|
nodiscard |
whether all the bits have been read
◆ position()
| std::size_t ADS::BitReader::position |
( |
void | | ) |
const |
|
nodiscard |
the place of the next bit
◆ read()
| Word ADS::BitReader::read |
( |
int | len | ) |
|
|
nodiscard |
the next \( \mathit{len} \) bits, the first in the least significant place
- Precondition
- \( \mathit{len} \le 64 \) and \( \mathit{len} \) bits are left
◆ readBinary()
| Word ADS::BitReader::readBinary |
( |
int | len | ) |
|
|
nodiscard |
the next \( \mathit{len} \) bits, the first in the most significant place, the field of writeBinary()
- Precondition
- \( \mathit{len} \le 64 \) and \( \mathit{len} \) bits are left
◆ readBit()
| bool ADS::BitReader::readBit |
( |
void | | ) |
|
|
nodiscard |
the next bit
- Precondition
- not atEnd()
◆ readUnary()
| std::uint64_t ADS::BitReader::readUnary |
( |
void | | ) |
|
|
nodiscard |
the number of zeros before the next 1, which is read too
In pseudocode (the unary code of chapter 11, Integer Coding, of Ferragina's book, beyond the book), a word at a time, \( p \) the place of the reader and \( \mathrm{ctz} \) the trailing zeros of a word:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{readUnary}() \cr
2 & \quad q \gets 0 \cr
3 & \quad \textbf{loop} \cr
4 & \qquad \mathit{len} \gets \min\{ 64 , \text{the bits left} \};
\ w \gets \mathrm{get}( p , \mathit{len} ) \cr
5 & \qquad \textbf{if}\ w \ne 0\ \textbf{then} \cr
6 & \qquad\quad z \gets \mathrm{ctz}( w );\ p \gets p + z + 1;
\ \textbf{return}\ q + z \cr
7 & \qquad q \gets q + \mathit{len};\ p \gets p + \mathit{len}
\end{array}}
\]
- Precondition
- a 1 is left
◆ seek()
| void ADS::BitReader::seek |
( |
std::size_t | p | ) |
|
moves to the place \( p \)
- Precondition
- \( p \) is at most the size of the bits
The documentation for this class was generated from the following file: