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

a stream of bits written at its end, on a BitVector More...

#include <ADS/succinct/BitStream.h>

Public member functions

 BitWriter (void)=default
 an empty stream
std::size_t size (void) const
 the bits written so far
void writeBit (bool b)
 appends the bit \( b \)
void write (Word v, int len)
 the \( \mathit{len} \) bits of \( v \), the least significant first
void writeBinary (Word v, int len)
 the \( \mathit{len} \) bits of \( v \), the most significant first
void writeUnary (std::uint64_t q)
 \( q \) zeros and a 1, the unary code \( U( q + 1 ) \)
const BitVector & bits (void) const
 the bits written
BitVector release (void)
 the bits written, which the writer leaves empty

Detailed description

a stream of bits written at its end, on a BitVector

Constructor and destructor documentation

◆ BitWriter()

ADS::BitWriter::BitWriter ( void )
default

an empty stream

Member function documentation

◆ bits()

const BitVector & ADS::BitWriter::bits ( void ) const
nodiscard

the bits written

◆ release()

BitVector ADS::BitWriter::release ( void )
nodiscard

the bits written, which the writer leaves empty

◆ size()

std::size_t ADS::BitWriter::size ( void ) const
nodiscard

the bits written so far

◆ write()

void ADS::BitWriter::write ( Word v,
int len )

the \( \mathit{len} \) bits of \( v \), the least significant first

Precondition
\( \mathit{len} \le 64 \) and \( v < 2^{\mathit{len}} \)

◆ writeBinary()

void ADS::BitWriter::writeBinary ( Word v,
int len )

the \( \mathit{len} \) bits of \( v \), the most significant first

In pseudocode (the binary code of chapter 11, Integer Coding, of Ferragina's book, beyond the book), the field turned around and appended as write() does:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{writeBinary}( v , \mathit{len} ) \cr 2 & \quad r \gets \text{the } \mathit{len} \text{ low bits of } v \text{ in the reverse order} \cr 3 & \quad \mathrm{write}( r , \mathit{len} ) \end{array}} \]

Precondition
\( \mathit{len} \le 64 \) and \( v < 2^{\mathit{len}} \)

◆ writeBit()

void ADS::BitWriter::writeBit ( bool b)

appends the bit \( b \)

◆ writeUnary()

void ADS::BitWriter::writeUnary ( std::uint64_t q)

\( q \) zeros and a 1, the unary code \( U( q + 1 ) \)

In pseudocode (the unary code of chapter 11, Integer Coding, of Ferragina's book, beyond the book), whole words of zeros first:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{writeUnary}( q ) \cr 2 & \quad \textbf{while}\ q \ge 64\ \textbf{do}\ \mathrm{write}( 0 , 64 );\ q \gets q - 64 \cr 3 & \quad \mathrm{write}( 2^q , q + 1 )\quad \triangleright\ q \ \text{zeros, then a 1} \end{array}} \]


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