This class, together with sibling HuffmanDecoder implements the well known Huffman compression
. The class uses type BitWriter to write the bit stream into an underlying BitBuffer.
The use of this class is quite straight forward:
- Create an instance of this class
- Feed the data to be compressed once to the algorithm using method CountSymbol
- Invoke method Generate
- Feed all data a second time using method Write.
Definition at line 22 of file huffman.inl.
◆ bw
BitWriter& alib::bitbuffer::ac_v1::HuffmanEncoder::bw |
|
protected |
The bit writer to use for encoding the data.
Definition at line 49 of file huffman.inl.
◆ MAX_CODE_LENGTH
int alib::bitbuffer::ac_v1::HuffmanEncoder::MAX_CODE_LENGTH = 64 |
|
staticconstexpr |
The maximum length of a huffman code. In theory, with 256 symbols, a maximum code length of 255 could occur. For this, each next symbol needed to have the double frequency than the previous. Hence, setting the value to 64, limits the encoded data size to 2^64 symbols, which should be more than enaugh for the next decades.
Definition at line 35 of file huffman.inl.
◆ MAX_WORDS
int alib::bitbuffer::ac_v1::HuffmanEncoder::MAX_WORDS = 2 |
|
staticconstexpr |
Codes are stored in two (this constant) words of size 32.
Definition at line 27 of file huffman.inl.
◆ symbols
Symbol alib::bitbuffer::ac_v1::HuffmanEncoder::symbols[256] |
|
protected |
◆ WORD_SIZE
int alib::bitbuffer::ac_v1::HuffmanEncoder::WORD_SIZE = 32 |
|
staticconstexpr |
Codes are stored in two words of size 32 (this constant)
Definition at line 25 of file huffman.inl.
◆ HuffmanEncoder()
alib::bitbuffer::ac_v1::HuffmanEncoder::HuffmanEncoder |
( |
BitWriter & | bitWriter | ) |
|
|
inline |
Constructor.
- Parameters
-
bitWriter | The bit writer to write the encoding information as well as the encoded symbols to. (Stored in field bw.) |
Definition at line 58 of file huffman.inl.
◆ CountSymbol()
void alib::bitbuffer::ac_v1::HuffmanEncoder::CountSymbol |
( |
uint8_t | symbol | ) |
|
|
inline |
Counts a symbol. This method has to be invoked for each byte to compress later.
- Parameters
-
symbol | The symbol to count. |
Definition at line 65 of file huffman.inl.
◆ Generate()
void alib::bitbuffer::ac_v1::HuffmanEncoder::Generate |
( |
| ) |
|
Generates the huffman encoding table and writes this information to the bit writer.
Definition at line 107 of file huffman.cpp.
◆ Write()
void alib::bitbuffer::ac_v1::HuffmanEncoder::Write |
( |
uint8_t | symbol | ) |
|
|
inline |
Writes the given symbol
to the bit stream.
- Parameters
-
symbol | The symbol to write. |
Definition at line 76 of file huffman.inl.
The documentation for this class was generated from the following files: