|
ADS
Algorithms and Data Structures
|
the decoder of a RangeEncoder on \( w \) bits More...
#include <ADS/compression/ArithmeticCoding.h>
Public member functions | |
| RangeDecoder (std::span< const std::uint8_t > bytes, int w=32) | |
| the decoder of the code bytes, which must outlive it | |
| std::uint64_t | maxTotal (void) const |
| the largest total of the counts, \( M / 4 \) | |
| std::uint64_t | target (std::uint64_t total) const |
| the cumulative count of the next symbol: it is the one whose counts \( [ \mathit{low} , \mathit{high} ) \) hold it | |
| void | consume (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, as the encoder did | |
the decoder of a RangeEncoder on \( w \) bits
|
explicit |
the decoder of the code bytes, which must outlive it
| void ADS::RangeDecoder::consume | ( | 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, as the encoder did
In pseudocode (Witten, Neal and Cleary, beyond the book), the expansions of RangeEncoder::encode() applied also to \( v \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{consume}( 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}\ \text{nothing} \cr 5 & \qquad \textbf{else if}\ L \ge M / 2\ \textbf{then}\ \text{subtract } M / 2 \text{ from } L , H , v \cr 6 & \qquad \textbf{else if}\ L \ge M / 4\ \textbf{and}\ H \le 3 M / 4 \ \textbf{then}\ \text{subtract } M / 4 \text{ from } L , H , v \cr 7 & \qquad \textbf{else return} \cr 8 & \qquad L \gets 2 L;\ H \gets 2 H;\ v \gets 2 v + \mathrm{nextBit}() \end{array}} \]
|
inlinenodiscard |
the largest total of the counts, \( M / 4 \)
|
nodiscard |
the cumulative count of the next symbol: it is the one whose counts \( [ \mathit{low} , \mathit{high} ) \) hold it
It inverts the narrowing of RangeEncoder::encode(), \( v \) the \( w \) bits read:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{target}( T ) \cr 2 & \quad \textbf{return}\ \lfloor ( ( v - L + 1 ) T - 1 ) / ( H - L ) \rfloor \end{array}} \]