Project
Loading...
Searching...
No Matches
o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB > Class Template Reference

#include <HuffmanCodec.h>

Inherits _BASE.

Classes

class  isless
 
class  isless< std::shared_ptr< T > >
 specialization for shared pointer More...
 
class  isless< T * >
 specialization for pointer types More...
 

Public Types

using base_type = _BASE
 
using code_type = Rep
 
using node_type = HuffmanNode< code_type >
 
using value_type = typename _BASE::value_type
 

Public Member Functions

 HuffmanModel ()
 
 ~HuffmanModel ()=default
 
int init (double v=1.)
 
code_type Encode (typename _BASE::value_type symbol, uint16_t &codeLength) const
 
value_type Decode (code_type code, uint16_t &codeLength) const
 
bool GenerateHuffmanTree ()
 
int assignCode (node_type *node)
 
int write (const char *filename, std::string method="zlib") const
 Write Huffman table to file.
 
int write (std::ostream &out) const
 Write Huffman table in self-consistent format to an output stream.
 
int read (const char *filename, std::string method="zlib")
 Read configuration from file.
 
int read (std::istream &in)
 Read configuration from stream The previous configuration is discarded.
 
void print () const
 

Static Public Attributes

static constexpr bool OrderMSB = orderMSB
 

Detailed Description

template<typename _BASE, typename Rep, bool orderMSB = true>
class o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >

Definition at line 240 of file HuffmanCodec.h.

Member Typedef Documentation

◆ base_type

template<typename _BASE , typename Rep , bool orderMSB = true>
using o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::base_type = _BASE

Definition at line 246 of file HuffmanCodec.h.

◆ code_type

template<typename _BASE , typename Rep , bool orderMSB = true>
using o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::code_type = Rep

Definition at line 247 of file HuffmanCodec.h.

◆ node_type

template<typename _BASE , typename Rep , bool orderMSB = true>
using o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::node_type = HuffmanNode<code_type>

Definition at line 248 of file HuffmanCodec.h.

◆ value_type

template<typename _BASE , typename Rep , bool orderMSB = true>
using o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::value_type = typename _BASE::value_type

Definition at line 249 of file HuffmanCodec.h.

Constructor & Destructor Documentation

◆ HuffmanModel()

template<typename _BASE , typename Rep , bool orderMSB = true>
o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::HuffmanModel ( )
inline

Definition at line 243 of file HuffmanCodec.h.

◆ ~HuffmanModel()

template<typename _BASE , typename Rep , bool orderMSB = true>
o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::~HuffmanModel ( )
default

Member Function Documentation

◆ assignCode()

template<typename _BASE , typename Rep , bool orderMSB = true>
int o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::assignCode ( node_type node)
inline

assign code to this node loop to right and left nodes

Code direction is determined by template parameter orderMSB being either true or false. Code can be built up in two directions, either with the bit of the parent node in the MSB or LSB. In the latter case, the bit of the parent node has to be right of the bit of child nodes, i.e. bits correspond to the current code length. A bit stream storing bits from MSB to LSB and then overwrapping to the MSBs of the next byte, requires to code to start with MSB.

TODO: implement iterator concept

Definition at line 423 of file HuffmanCodec.h.

◆ Decode()

template<typename _BASE , typename Rep , bool orderMSB = true>
value_type o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::Decode ( code_type  code,
uint16_t &  codeLength 
) const
inline

Decode bit pattern

The caller provides a bit field determined by the class' template parameter, The number of decoded bits is indicated in the codeLength parameter after decoding.

  • code [in] code bits
  • codeLength [OUT] number of decoded bits
    Returns
    value, valid if codeLength > 0

Definition at line 290 of file HuffmanCodec.h.

◆ Encode()

template<typename _BASE , typename Rep , bool orderMSB = true>
code_type o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::Encode ( typename _BASE::value_type  symbol,
uint16_t &  codeLength 
) const
inline

Encode value

  • symbol [in] symbol to be encoded
  • codeLength [OUT] code length, number of LSBs
    Returns
    Huffman code, valid if codeLength > 0

Definition at line 261 of file HuffmanCodec.h.

◆ GenerateHuffmanTree()

template<typename _BASE , typename Rep , bool orderMSB = true>
bool o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::GenerateHuffmanTree ( )
inline

Combine and sort nodes to build a binary tree TODO: separate data structures for tree and leaf nodes to optimize storage

Definition at line 376 of file HuffmanCodec.h.

◆ init()

template<typename _BASE , typename Rep , bool orderMSB = true>
int o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::init ( double  v = 1.)
inline

Definition at line 252 of file HuffmanCodec.h.

◆ print()

template<typename _BASE , typename Rep , bool orderMSB = true>
void o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::print ( ) const
inline

Definition at line 615 of file HuffmanCodec.h.

◆ read() [1/2]

template<typename _BASE , typename Rep , bool orderMSB = true>
int o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::read ( const char filename,
std::string  method = "zlib" 
)
inline

Read configuration from file.

Read configuration text file, can be in compressed format, supported methods: gzip, zlib, bzip2, and lzma

Definition at line 492 of file HuffmanCodec.h.

◆ read() [2/2]

template<typename _BASE , typename Rep , bool orderMSB = true>
int o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::read ( std::istream &  in)
inline

Read configuration from stream The previous configuration is discarded.

The text file contains a self-consistent representatio of the Huffman tree, one node definition per line. Each node has an index (corresponding to the line number). The tree nodes hold the indices of their child nodes. Leave node format: index value weight codelen code Tree node format: index left_index right_index

Definition at line 508 of file HuffmanCodec.h.

◆ write() [1/2]

template<typename _BASE , typename Rep , bool orderMSB = true>
int o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::write ( const char filename,
std::string  method = "zlib" 
) const
inline

Write Huffman table to file.

The file can be compressed on-the-fly, supported methods: gzip, zlib, bzip2, and lzma

Configuration is written in self-consistent text file format.

Definition at line 469 of file HuffmanCodec.h.

◆ write() [2/2]

template<typename _BASE , typename Rep , bool orderMSB = true>
int o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::write ( std::ostream &  out) const
inline

Write Huffman table in self-consistent format to an output stream.

Definition at line 478 of file HuffmanCodec.h.

Member Data Documentation

◆ OrderMSB

template<typename _BASE , typename Rep , bool orderMSB = true>
constexpr bool o2::data_compression::HuffmanModel< _BASE, Rep, orderMSB >::OrderMSB = orderMSB
staticconstexpr

Definition at line 250 of file HuffmanCodec.h.


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