JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::serio::huffman< Signature, Algo > Class Template Referencefinal

High-performance Huffman encoder/decoder. More...

#include <jh/serialize_io/huffman.h>

Static Public Member Functions

static void build_code_length (const std::vector< node > &pool, int root, jh::pod::array< std::uint8_t, table_size > &len_tbl)=delete
static void build_canonical_codes (const jh::pod::array< std::uint8_t, table_size > &len_tbl, table_t &tbl)=delete
static void build_canonical_decoder (const jh::pod::array< std::uint8_t, table_size > &len_tbl, canonical_decoder &dec)=delete
static std::string canonical_decode (std::istream &is, std::uint64_t total_bits, const canonical_decoder &dec)=delete
static void compress (std::ostream &os, std::string_view input)
 Compress a string into the provided binary output stream.
static std::string decompress (std::istream &is)
 Decompress a Huffman-encoded binary stream.

Detailed Description

template<jh::meta::TStr Signature, huff_algo Algo = huff_algo::huff256_canonical>
class jh::serio::huffman< Signature, Algo >

High-performance Huffman encoder/decoder.

Features

  • ASCII (128 symbols) and full-byte (256 symbols) support
  • Canonical encoding for deterministic prefix tables
  • Tree-based Huffman for legacy compatibility
  • Guaranteed prefix-free encoding with max depth 32
  • Exception-safe streaming I/O

Generated file format

  • Header — user-defined signature (Signature)
  • Canonical mode: code-length table, total bits, bitstream
  • Standard mode: full frequency table, total bits, bitstream
Template Parameters
SignatureUser-defined compile-time signature written to the output stream as a format magic number.
AlgoHuffman codec variant (tree-based or canonical).

Member Function Documentation

◆ compress()

template<jh::meta::TStr Signature, huff_algo Algo = huff_algo::huff256_canonical>
void jh::serio::huffman< Signature, Algo >::compress ( std::ostream & os,
std::string_view input )
inlinestatic

Compress a string into the provided binary output stream.

Format written depends on Algo:

  • Canonical: code-lengths → total bits → bitstream
  • Standard: full frequency table → total bits → bitstream
Parameters
osOutput binary stream.
inputInput string to compress.
Exceptions
std::runtime_errorIf ASCII-only algorithm receives >127 symbol.

◆ decompress()

template<jh::meta::TStr Signature, huff_algo Algo = huff_algo::huff256_canonical>
std::string jh::serio::huffman< Signature, Algo >::decompress ( std::istream & is)
inlinestatic

Decompress a Huffman-encoded binary stream.

Parameters
isInput stream positioned at the beginning of the stored format.
Returns
Decoded textual data.
Exceptions
std::runtime_errorOn signature mismatch or malformed input.

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