90#ifndef __ADS_CanonicalHuffman
91 #define __ADS_CanonicalHuffman
108#include <type_traits>
131template<
class C ,
class F >
132[[nodiscard]] std::map< C , int >
157template<
class C ,
class F >
158[[nodiscard]] std::map< C ,
206 [[nodiscard]]
const std::map< C , int > &
lengths(
void )
const {
211 [[nodiscard]]
int maxLength(
void )
const {
return( f_max ); }
220 [[nodiscard]] std::string
code(
const C & c )
const;
240 [[nodiscard]] std::vector< std::uint8_t >
241 encode( std::span< const C > text )
const;
262 [[nodiscard]] std::vector< C >
263 decode(
const std::vector< std::uint8_t > & bits , std::size_t n )
const;
267 std::map< C , int > f_len;
268 std::map< C , std::uint64_t > f_code;
269 std::vector< std::uint64_t > f_fc;
270 std::vector< std::vector< C > > f_symb;
283#include "ADS/compression/impl/CanonicalHuffman.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The code of Huffman (reality check of section 14.4): a prefix code, no code being a prefix of another...
The bits of the compressors of this folder, packed in bytes, since their input and their output are s...
std::vector< std::uint8_t > encode(std::span< const C > text) const
the codes of the symbols of text, packed in bytes
std::uint64_t firstCode(int l) const
, the value of the first code of length
static CanonicalHuffman fromFrequencies(const std::map< C, F > &freq)
the canonical code of the code of Huffman of the frequencies
int maxLength(void) const
the longest length
Definition CanonicalHuffman.h:211
const std::map< C, int > & lengths(void) const
the lengths of the codes
Definition CanonicalHuffman.h:206
void encode(const C &c, PackedBitWriter &w) const
appends the code of to
std::string code(const C &c) const
the code of , a string of '0' and '1'
std::vector< C > decode(const std::vector< std::uint8_t > &bits, std::size_t n) const
the first symbols encoded in bits, each by decode() above
C decode(PackedBitReader &r) const
the symbol whose code is next in
CanonicalHuffman(const std::map< C, int > &lengths)
the canonical code of the lengths
C symbol_type
the type of the symbols
Definition CanonicalHuffman.h:173
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::map< C, int > limitedLengths(const std::map< C, F > &freq, int L)
the lengths of a code of Huffman of no length above , by halving the frequencies (rounding up) until ...
std::map< C, int > huffmanLengths(const std::map< C, F > &freq)
the lengths of the codes of Huffman [see Huffman.h] of the symbols with the frequencies freq