High-performance Huffman encoder/decoder.
More...
#include <jh/serialize_io/huffman.h>
|
|
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.
|
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
-
| Signature | User-defined compile-time signature written to the output stream as a format magic number. |
| Algo | Huffman codec variant (tree-based or canonical). |
◆ compress()
| 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
-
| os | Output binary stream. |
| input | Input string to compress. |
- Exceptions
-
| std::runtime_error | If ASCII-only algorithm receives >127 symbol. |
◆ decompress()
Decompress a Huffman-encoded binary stream.
- Parameters
-
| is | Input stream positioned at the beginning of the stored format. |
- Returns
- Decoded textual data.
- Exceptions
-
| std::runtime_error | On signature mismatch or malformed input. |
The documentation for this class was generated from the following file: