93#ifndef __ADS_ArithmeticCoding
94 #define __ADS_ArithmeticCoding
111#include <string_view>
143[[nodiscard]] std::pair< Rational , Rational >
145 const std::map< C , Rational > & prob );
170[[nodiscard]] std::string
172 const std::map< C , Rational > & prob );
192[[nodiscard]] std::vector< C >
194 const std::map< C , Rational > & prob );
213 [[nodiscard]] std::uint64_t
maxTotal(
void )
const {
return( f_M / 4 ); }
240 void encode( std::uint64_t low , std::uint64_t high , std::uint64_t total );
246 [[nodiscard]] std::vector< std::uint8_t >
finish(
void );
249 [[nodiscard]] std::size_t
bits(
void )
const {
return( f_out.size() ); }
257 std::uint64_t f_low = 0;
258 std::uint64_t f_high;
259 std::size_t f_pending = 0;
276 explicit RangeDecoder( std::span< const std::uint8_t > bytes ,
int w = 32 );
279 [[nodiscard]] std::uint64_t
maxTotal(
void )
const {
return( f_M / 4 ); }
295 [[nodiscard]] std::uint64_t
target( std::uint64_t total )
const;
322 void consume( std::uint64_t low , std::uint64_t high , std::uint64_t total );
327 std::uint64_t f_low = 0;
328 std::uint64_t f_high;
329 std::uint64_t f_v = 0;
360[[nodiscard]] std::vector< std::uint8_t >
362 const std::map< C , std::uint64_t > & counts ,
int w = 32 );
382[[nodiscard]] std::vector< C >
384 const std::map< C , std::uint64_t > & counts ,
int w = 32 );
411[[nodiscard]]
inline std::vector< std::uint8_t >
413 std::uint32_t sigma );
437[[nodiscard]]
inline std::vector< std::uint32_t >
440 std::uint32_t sigma );
446[[nodiscard]]
inline std::vector< std::uint8_t >
451[[nodiscard]]
inline std::string
463#include "ADS/compression/impl/ArithmeticCoding.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The bits of the compressors of this folder, packed in bytes, since their input and their output are s...
The exact rational numbers of Knuth (section 4.5.1 of The Art of Computer Programming),...
reads the bits of a sequence of bytes in the order of a PackedBitWriter, and zeros past its end
Definition PackedBits.h:108
a growing sequence of bits, packed in bytes, the first bit in the most significant bit of the first b...
Definition PackedBits.h:70
std::uint64_t maxTotal(void) const
the largest total of the counts,
Definition ArithmeticCoding.h:279
void consume(std::uint64_t low, std::uint64_t high, std::uint64_t total)
narrows the interval to the symbol of cumulative counts out of total, as the encoder did
RangeDecoder(std::span< const std::uint8_t > bytes, int w=32)
the decoder of the code bytes, which must outlive it
std::uint64_t target(std::uint64_t total) const
the cumulative count of the next symbol: it is the one whose counts hold it
std::uint64_t maxTotal(void) const
the largest total of the counts,
Definition ArithmeticCoding.h:213
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
Definition ArithmeticCoding.h:249
void encode(std::uint64_t low, std::uint64_t high, std::uint64_t total)
narrows the interval to the symbol of cumulative counts out of total
RangeEncoder(int w=32)
the encoder on bits, with the interval ,
std::vector< std::uint32_t > adaptiveArithmeticDecode(std::span< const std::uint8_t > code, std::size_t n, std::uint32_t sigma)
the symbols of the adaptive arithmetic code in
std::string arithmeticCodeExact(std::span< const C > text, const std::map< C, Rational > &prob)
the arithmetic code of text: the first bits of , a string of '0' and '1'
std::vector< std::uint8_t > adaptiveArithmeticEncode(std::span< const std::uint32_t > x, std::uint32_t sigma)
the adaptive arithmetic code of the symbols of in
std::pair< Rational, Rational > arithmeticInterval(std::span< const C > text, const std::map< C, Rational > &prob)
the interval of text, as the pair
std::vector< C > arithmeticDecode(std::span< const std::uint8_t > code, std::size_t n, const std::map< C, std::uint64_t > &counts, int w=32)
the symbols of the code with the static model of the counts
std::vector< std::uint8_t > arithmeticEncode(std::span< const C > text, const std::map< C, std::uint64_t > &counts, int w=32)
the arithmetic code of text with the static model of the counts
std::vector< C > arithmeticDecodeExact(const std::string &bits, std::size_t n, const std::map< C, Rational > &prob)
the text of symbols of the code bits