ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
HuffmanEncoder Class Reference

Description:

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 28 of file huffman.hpp.

#include <huffman.hpp>

Collaboration diagram for HuffmanEncoder:
[legend]

Inner Type Index:

struct  Symbol
 

Public Static Field Index:

static constexpr int MAX_CODE_LENGTH = 64
 
static constexpr int MAX_WORDS = 2
 
static constexpr int WORD_SIZE = 32
 

Public Method Index:

 HuffmanEncoder (BitWriter &bitWriter)
 
ALIB_FORCE_INLINE void CountSymbol (uint8_t symbol)
 
ALIB_API void Generate ()
 Generates the huffman encoding table and writes this information to the bit writer.
 
void Write (uint8_t symbol)
 

Protected Field Index:

BitWriterbw
 The bit writer to use for encoding the data.
 
Symbol symbols [256]
 The symbol table.
 

Field Details:

◆ bw

BitWriter& bw
protected

The bit writer to use for encoding the data.

Definition at line 55 of file huffman.hpp.

◆ MAX_CODE_LENGTH

int 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 41 of file huffman.hpp.

◆ MAX_WORDS

int MAX_WORDS = 2
staticconstexpr

Codes are stored in two (this constant) words of size 32.

Definition at line 33 of file huffman.hpp.

◆ symbols

Symbol symbols[256]
protected

The symbol table.

Definition at line 56 of file huffman.hpp.

◆ WORD_SIZE

int WORD_SIZE = 32
staticconstexpr

Codes are stored in two words of size 32 (this constant)

Definition at line 31 of file huffman.hpp.

Constructor(s) / Destructor Details:

◆ HuffmanEncoder()

HuffmanEncoder ( BitWriter & bitWriter)
inline

Constructor.

Parameters
bitWriterThe bit writer to write the encoding information as well as the encoded symbols to. (Stored in field bw.)

Definition at line 64 of file huffman.hpp.

Method Details:

◆ CountSymbol()

ALIB_FORCE_INLINE void CountSymbol ( uint8_t symbol)
inline

Counts a symbol. This method has to be invoked for each byte to compress later.

Parameters
symbolThe symbol to count.

Definition at line 72 of file huffman.hpp.

◆ Generate()

Generates the huffman encoding table and writes this information to the bit writer.

Definition at line 96 of file huffman.cpp.

Here is the call graph for this function:

◆ Write()

void Write ( uint8_t symbol)
inline

Writes the given symbol to the bit stream.

Parameters
symbolThe symbol to write.

Definition at line 85 of file huffman.hpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: