45 init(maxLength, codeCount, codes, lengths, symbols);
51 assert(codeCount > 0);
57 for (
size_t i = 0; i < codeCount; i++)
58 maxLength =
MAX(maxLength, lengths[i]);
60 assert(maxLength <= 32);
65 for (
size_t i = 0; i < codeCount; i++) {
67 uint32 symbol = symbols ? symbols[i] : i;
70 _codes[lengths[i] - 1].push_back(
Symbol(codes[i], symbol));
81 for (
size_t i = 0; i <
_symbols.size(); i++)
82 _symbols[i]->symbol = symbols ? *symbols++ : i;
88 for (
size_t i = 0; i <
_codes.size(); i++) {
91 for (CodeList::const_iterator cCode =
_codes[i].begin(); cCode !=
_codes[i].end(); ++cCode)
92 if (code == cCode->code)
void setSymbols(const uint32 *symbols=0)
Modify the codes' symbols.
Symbol(uint32 c, uint32 s)
const uint8 * lengths
The lengths of the individual codes.
uint32 getSymbol(BitStream &bits) const
Return the next symbol in the bitstream.
Basic exceptions to throw.
Utility templates and functions.
uint8 maxLength
Maximal code length. If 0, it's searched for.
Huffman(uint8 maxLength, size_t codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols=0)
Construct a Huffman decoder.
SymbolList _symbols
Sorted list of pointers to the symbols.
const uint32 * symbols
The symbols, 0 if identical to the codes.
virtual void addBit(uint32 &x, size_t n)=0
Add a bit to the n-bit value x, making it an (n+1)-bit value.
Decompressing Huffman codes.
CodeLists _codes
Lists of codes and their symbols, sorted by code length.
size_t codeCount
Number of codes.
const uint32 * codes
The actual codes.
void init(uint8 maxLength, size_t codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols)