|
ADS
Algorithms and Data Structures
|
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 | |
the integer arithmetic encoder of Witten, Neal and Cleary on \( w \) bits
|
explicit |
the encoder on \( w \) bits, with the interval \( [ 0 , M ) \), \( M = 2^w \)
|
inlinenodiscard |
the number of bits emitted
| 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}} \]
|
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.
|
inlinenodiscard |
the largest total of the counts, \( M / 4 \)