Tree Compression with Top Trees Revisited
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
HuffmanBuilder< SymbolType > Class Template Reference

Generic Huffman Code Builder. Only constructs code, does not en-/decode. More...

#include <Huffman.h>

Collaboration diagram for HuffmanBuilder< SymbolType >:
Collaboration graph
[legend]

Public Types

typedef std::vector< bool > HuffCode
 

Public Member Functions

 HuffmanBuilder ()
 
void addItem (const SymbolType &symbol)
 add an occurence to the frequency statistics More...
 
template<class InputIterator >
void addItems (InputIterator begin, InputIterator end)
 add a sequence of occurences to the frequency statistics More...
 
void construct ()
 Construct a Huffman code for the symols encountered, and the frequencies with which they were encountered. More...
 
int getNumSymbols () const
 Get the number of different symbols encountered. More...
 
int getNumItems () const
 Get the total number of occurences encountered. More...
 
HuffCode getCode (const SymbolType &symbol)
 Get the code for a symbol. Must to have called construct() before. More...
 
int getCodeLength (const SymbolType &symbol) const
 Get the length of a symbol's code. Need to have called construct() before. More...
 
long long getBitsNeeded () const
 
long long getBitsForTree () const
 
long long getBitsForTableLabels () const
 
std::string toString () const
 

Protected Member Functions

void constructTree ()
 Construct a Huffman tree from the symbols encountered and the frequencies observed. More...
 
void computeCodes (const int nodeId, HuffCode prefix)
 Recursively assign codes to the symbols. More...
 

Protected Attributes

int numItems
 
std::unordered_map< SymbolType, int > symbols
 
std::vector< int > frequencies
 
std::vector< HuffCodecodes
 
std::vector< HuffNode * > nodes
 

Friends

std::ostream & operator<< (std::ostream &os, const HuffmanBuilder &huff)
 Print summary to an ostream. More...
 

Detailed Description

template<typename SymbolType>
class HuffmanBuilder< SymbolType >

Generic Huffman Code Builder. Only constructs code, does not en-/decode.

Definition at line 43 of file Huffman.h.

Member Typedef Documentation

template<typename SymbolType>
typedef std::vector<bool> HuffmanBuilder< SymbolType >::HuffCode

Definition at line 45 of file Huffman.h.

Constructor & Destructor Documentation

template<typename SymbolType>
HuffmanBuilder< SymbolType >::HuffmanBuilder ( )
inline

Definition at line 46 of file Huffman.h.

Member Function Documentation

template<typename SymbolType>
void HuffmanBuilder< SymbolType >::addItem ( const SymbolType &  symbol)
inline

add an occurence to the frequency statistics

Definition at line 49 of file Huffman.h.

template<typename SymbolType>
template<class InputIterator >
void HuffmanBuilder< SymbolType >::addItems ( InputIterator  begin,
InputIterator  end 
)
inline

add a sequence of occurences to the frequency statistics

Definition at line 61 of file Huffman.h.

template<typename SymbolType>
void HuffmanBuilder< SymbolType >::computeCodes ( const int  nodeId,
HuffCode  prefix 
)
inlineprotected

Recursively assign codes to the symbols.

Definition at line 185 of file Huffman.h.

template<typename SymbolType>
void HuffmanBuilder< SymbolType >::construct ( )
inline

Construct a Huffman code for the symols encountered, and the frequencies with which they were encountered.

Definition at line 68 of file Huffman.h.

template<typename SymbolType>
void HuffmanBuilder< SymbolType >::constructTree ( )
inlineprotected

Construct a Huffman tree from the symbols encountered and the frequencies observed.

Definition at line 164 of file Huffman.h.

template<typename SymbolType>
long long HuffmanBuilder< SymbolType >::getBitsForTableLabels ( ) const
inline

Get the number of bits that are required to store the labels to the table entries, as fixed-length codes.

Definition at line 137 of file Huffman.h.

template<typename SymbolType>
long long HuffmanBuilder< SymbolType >::getBitsForTree ( ) const
inline

Get the number of bits to encode the structure of the huffman table/tree Codes only code lengths (in unary)

Definition at line 121 of file Huffman.h.

template<typename SymbolType>
long long HuffmanBuilder< SymbolType >::getBitsNeeded ( ) const
inline

Get the number of bits needed to encode the occurrences encountered with the code that was calculated (need to have called construct() before).

Returns
size in bits for coding the items and the structure of the huffman table

Definition at line 106 of file Huffman.h.

template<typename SymbolType>
HuffCode HuffmanBuilder< SymbolType >::getCode ( const SymbolType &  symbol)
inline

Get the code for a symbol. Must to have called construct() before.

Definition at line 92 of file Huffman.h.

template<typename SymbolType>
int HuffmanBuilder< SymbolType >::getCodeLength ( const SymbolType &  symbol) const
inline

Get the length of a symbol's code. Need to have called construct() before.

Definition at line 98 of file Huffman.h.

template<typename SymbolType>
int HuffmanBuilder< SymbolType >::getNumItems ( ) const
inline

Get the total number of occurences encountered.

Definition at line 87 of file Huffman.h.

template<typename SymbolType>
int HuffmanBuilder< SymbolType >::getNumSymbols ( ) const
inline

Get the number of different symbols encountered.

Definition at line 82 of file Huffman.h.

template<typename SymbolType>
std::string HuffmanBuilder< SymbolType >::toString ( ) const
inline

Get a string representation, including the symbols, their codes and absolute as well as relative frequencies.

Definition at line 143 of file Huffman.h.

Friends And Related Function Documentation

template<typename SymbolType>
std::ostream& operator<< ( std::ostream &  os,
const HuffmanBuilder< SymbolType > &  huff 
)
friend

Print summary to an ostream.

Definition at line 158 of file Huffman.h.

Member Data Documentation

template<typename SymbolType>
std::vector<HuffCode> HuffmanBuilder< SymbolType >::codes
protected

Definition at line 201 of file Huffman.h.

template<typename SymbolType>
std::vector<int> HuffmanBuilder< SymbolType >::frequencies
protected

Definition at line 200 of file Huffman.h.

template<typename SymbolType>
std::vector<HuffNode*> HuffmanBuilder< SymbolType >::nodes
protected

Definition at line 202 of file Huffman.h.

template<typename SymbolType>
int HuffmanBuilder< SymbolType >::numItems
protected

Definition at line 198 of file Huffman.h.

template<typename SymbolType>
std::unordered_map<SymbolType, int> HuffmanBuilder< SymbolType >::symbols
protected

Definition at line 199 of file Huffman.h.


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