79 int bitsLeft= rec.wordLength;
82 "Try to write symbol unknown to Huffman table: {}, ", symbol, bitsLeft )
85 "Try to write symbol unknown to Huffman table: ", symbol )
89 auto* word= rec.words;
92 bw.Write<32>( *word );
97 bw.Write(bitsLeft, *word );
162 if( node->
left ==
nullptr)
165 auto v=
br.Read<1>();
166 node= v ? node->
right
Reads bits from a BitBufferBase.
Writes bits into a BitBufferBase.
int npNext
The next node in nodePool to use.
static constexpr int MAX_NODES
The maximum number of nodes in the tree.
HuffmanDecoder(BitReader &bitReader)
Node tree
The root node of the symbol tree.
Node nodePool[MAX_NODES]
Pre-allocated node objects.
BitReader & br
The bit reader given in the constructor.
BitWriter & bw
The bit writer to use for encoding the data.
static constexpr int WORD_SIZE
HuffmanEncoder(BitWriter &bitWriter)
void Write(uint8_t symbol)
static constexpr int MAX_CODE_LENGTH
void CountSymbol(uint8_t symbol)
Symbol symbols[256]
The symbol table.
ALIB_DLL void Generate()
Generates the huffman encoding table and writes this information to the bit writer.
static constexpr int MAX_WORDS
#define ALIB_ASSERT_ERROR(cond, domain,...)
int ShiftOpRHS
Type alias in namespace alib.
Internal struct representing nodes of the huffman code tree.
Node * right
The right child node.
Node * left
The left child node.
std::size_t frequency
The number of occurrences of the symbol.
uint32_t words[MAX_WORDS]
The bitcode of the symbol.
alib::ShiftOpRHS wordLength
0: symbol not used, otherwise between 1 and 255.