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

the integer arithmetic encoder of Witten, Neal and Cleary on \( w \) bits More...

#include <ADS/compression/ArithmeticCoding.h>

Public member functions

 RangeEncoder (int w=32)
 the encoder on \( w \) bits, with the interval \( [ 0 , M ) \), \( M = 2^w \)
std::uint64_t maxTotal (void) const
 the largest total of the counts, \( M / 4 \)
void encode (std::uint64_t low, std::uint64_t high, std::uint64_t total)
 narrows the interval to the symbol of cumulative counts \( [ \mathit{low} , \mathit{high} ) \) out of total
std::vector< std::uint8_t > finish (void)
 the bits that end the code, and the code
std::size_t bits (void) const
 the number of bits emitted

Detailed description

the integer arithmetic encoder of Witten, Neal and Cleary on \( w \) bits

Constructor and destructor documentation

◆ RangeEncoder()

ADS::RangeEncoder::RangeEncoder ( int w = 32)
explicit

the encoder on \( w \) bits, with the interval \( [ 0 , M ) \), \( M = 2^w \)

Precondition
\( 2 \le w \le 32 \)

Member function documentation

◆ bits()

std::size_t ADS::RangeEncoder::bits ( void ) const
inlinenodiscard

the number of bits emitted

◆ encode()

void ADS::RangeEncoder::encode ( std::uint64_t low,
std::uint64_t high,
std::uint64_t total )

narrows the interval to the symbol of cumulative counts \( [ \mathit{low} , \mathit{high} ) \) out of total

In pseudocode (Witten, Neal and Cleary, beyond the book), \( [ L , H ) \) the interval and \( p \) the underflows pending:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{encode}( a , b , T ) \cr 2 & \quad r \gets H - L;\ H \gets L + \lfloor r b / T \rfloor; \ L \gets L + \lfloor r a / T \rfloor \cr 3 & \quad \textbf{loop} \cr 4 & \qquad \textbf{if}\ H \le M / 2\ \textbf{then}\ \mathrm{emit}( 0 ) \quad \triangleright\ \text{then } 1^p \text{, and } p \gets 0 \cr 5 & \qquad \textbf{else if}\ L \ge M / 2\ \textbf{then} \ \mathrm{emit}( 1 );\ L \gets L - M / 2;\ H \gets H - M / 2 \cr 6 & \qquad \textbf{else if}\ L \ge M / 4\ \textbf{and}\ H \le 3 M / 4 \ \textbf{then}\ p \gets p + 1;\ L \gets L - M / 4;\ H \gets H - M / 4 \cr 7 & \qquad \textbf{else return} \cr 8 & \qquad L \gets 2 L;\ H \gets 2 H \end{array}} \]

Precondition
\( \mathit{low} < \mathit{high} \le \mathit{total} \le \) maxTotal()
Invariant
\( H - L > M / 4 \) after the expansions

◆ finish()

std::vector< std::uint8_t > ADS::RangeEncoder::finish ( void )
nodiscard

the bits that end the code, and the code

It emits two bits and the pending ones, 01 if \( L < M / 4 \) and 10 otherwise, which pick a point of \( [ L , H ) \) whatever follows.

◆ maxTotal()

std::uint64_t ADS::RangeEncoder::maxTotal ( void ) const
inlinenodiscard

the largest total of the counts, \( M / 4 \)


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