|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Incremental FGK decoder accepting arbitrarily fragmented bits. More...
#include <Adaptive_Huffman.H>
Public Member Functions | |
| Adaptive_Huffman_Decoder () noexcept=default | |
| Construct a decoder with an empty model and no pending bits. | |
| void | reset () noexcept |
| Clear the tree, pending bits and error state in O(256) time. | |
| std::uint64_t | symbols_processed () const noexcept |
| Return the number of complete bytes decoded. | |
| size_t | distinct_symbols () const noexcept |
| Return the number of different decoded byte values. | |
| std::uint64_t | frequency (const unsigned char symbol) const noexcept |
| Return the current frequency of a decoded byte. | |
| bool | has_pending_symbol () const noexcept |
| Test whether a tree path or NYT literal is incomplete. | |
| bool | decode_bit (const unsigned int bit, unsigned char &symbol) |
| Consume one bit and emit a byte if its codeword is complete. | |
| size_t | decode (const BitArray &input, std::string &output) |
| Decode a bit chunk and append all complete bytes to a string. | |
| void | finish () const |
| Verify that an externally framed message ended at a byte boundary. | |
Private Attributes | |
| adaptive_huffman_detail::Model | model |
| Owned adaptive tree. | |
| int | current = model.root |
| Node reached by the partial codeword. | |
| unsigned int | literal = 0 |
| Partial, most-significant-bit-first byte. | |
| unsigned int | literal_bits = 0 |
| Number of literal bits collected. | |
| bool | failed = false |
| Malformed input or a lost output byte requires reset. | |
Incremental FGK decoder accepting arbitrarily fragmented bits.
A byte is emitted as soon as its last bit arrives. Partial tree paths and partial NYT literals survive across calls, so chunks may end at any bit position. Call finish() at the externally known end of the message to check that no partial codeword remains.
Memory, update complexity, copying, counter limits and thread-safety are the same as for Adaptive_Huffman_Encoder. Each bit costs O(1), plus an O((h + 1) log 256) tree update when a byte is completed. A copy includes any partially decoded codeword.
Definition at line 361 of file Adaptive_Huffman.H.
|
defaultnoexcept |
Construct a decoder with an empty model and no pending bits.
|
inline |
Decode a bit chunk and append all complete bytes to a string.
| input | Next encoded bits; no byte alignment is required. | |
| [out] | output | String to append to, preserving embedded NULs. |
| std::invalid_argument,std::domain_error | or std::overflow_error under the same conditions as decode_bit(), for a chunk that is not empty: an empty one consumes nothing and returns zero. |
| std::bad_alloc | or std::length_error if output cannot grow. The decoder has then counted a byte that is not in output, so it is left failed: every later call throws std::domain_error until reset(). Use decode_bit() to control the allocation of the output, or to go on after it fails. |
Definition at line 494 of file Adaptive_Huffman.H.
References decode_bit(), failed, output, and Aleph::BitArray::size().
Referenced by TEST_F().
|
inline |
Consume one bit and emit a byte if its codeword is complete.
| bit | Next encoded bit, either 0 or 1. | |
| [out] | symbol | Decoded byte; left unchanged when returning false. |
| std::out_of_range | if bit is not binary; no state is changed. |
| std::invalid_argument | if NYT introduces a byte already seen, or is used after all 256 bytes have appeared. Call reset() on both peers before starting a new message after this error. |
| std::domain_error | if called, without reset(), after malformed input or after decode() could not append a decoded byte. |
| std::overflow_error | if the frequency limit has been reached. |
Definition at line 430 of file Adaptive_Huffman.H.
References ah_domain_error_if, ah_invalid_argument, ah_out_of_range_error_if, Aleph::adaptive_huffman_detail::Model::alphabet_size, Aleph::adaptive_huffman_detail::Model::check_capacity(), current, Aleph::adaptive_huffman_detail::Model::distinct, failed, Aleph::adaptive_huffman_detail::Model::Node::is_leaf(), Aleph::adaptive_huffman_detail::Model::leaves, Aleph::adaptive_huffman_detail::Model::Node::left, literal, literal_bits, model, Aleph::adaptive_huffman_detail::Model::nodes, Aleph::adaptive_huffman_detail::Model::nyt, Aleph::adaptive_huffman_detail::Model::Node::right, Aleph::adaptive_huffman_detail::Model::root, Aleph::adaptive_huffman_detail::Model::Node::symbol, Aleph::adaptive_huffman_detail::Model::update(), and value.
Referenced by decode(), TEST_F(), TEST_F(), and adaptive_huffman_demo::trace().
|
inlinenoexcept |
Return the number of different decoded byte values.
Definition at line 393 of file Adaptive_Huffman.H.
References Aleph::adaptive_huffman_detail::Model::distinct, and model.
|
inline |
Verify that an externally framed message ended at a byte boundary.
| std::invalid_argument | if a codeword or NYT literal is incomplete. |
| std::domain_error | after malformed input, or after decode() could not append a decoded byte, until reset(). |
Definition at line 522 of file Adaptive_Huffman.H.
References ah_domain_error_if, ah_invalid_argument_if, failed, and has_pending_symbol().
Referenced by TEST_F(), TEST_F(), and adaptive_huffman_demo::trace().
|
inlinenoexcept |
Return the current frequency of a decoded byte.
| symbol | Byte to query. |
Definition at line 402 of file Adaptive_Huffman.H.
References Aleph::adaptive_huffman_detail::Model::leaves, model, Aleph::adaptive_huffman_detail::Model::nodes, and Aleph::adaptive_huffman_detail::Model::Node::weight.
|
inlinenoexcept |
Test whether a tree path or NYT literal is incomplete.
Definition at line 411 of file Adaptive_Huffman.H.
References current, literal_bits, model, and Aleph::adaptive_huffman_detail::Model::root.
Referenced by finish().
|
inlinenoexcept |
Clear the tree, pending bits and error state in O(256) time.
Definition at line 374 of file Adaptive_Huffman.H.
References current, failed, literal, literal_bits, model, Aleph::adaptive_huffman_detail::Model::reset(), and Aleph::adaptive_huffman_detail::Model::root.
Referenced by TEST_F().
|
inlinenoexcept |
Return the number of complete bytes decoded.
Definition at line 385 of file Adaptive_Huffman.H.
References model, Aleph::adaptive_huffman_detail::Model::nodes, Aleph::adaptive_huffman_detail::Model::root, and Aleph::adaptive_huffman_detail::Model::Node::weight.
Referenced by TEST_F().
|
private |
Node reached by the partial codeword.
Definition at line 364 of file Adaptive_Huffman.H.
Referenced by decode_bit(), has_pending_symbol(), and reset().
|
private |
Malformed input or a lost output byte requires reset.
Definition at line 367 of file Adaptive_Huffman.H.
Referenced by decode(), decode_bit(), finish(), and reset().
|
private |
Partial, most-significant-bit-first byte.
Definition at line 365 of file Adaptive_Huffman.H.
Referenced by decode_bit(), and reset().
|
private |
Number of literal bits collected.
Definition at line 366 of file Adaptive_Huffman.H.
Referenced by decode_bit(), has_pending_symbol(), and reset().
|
private |
Owned adaptive tree.
Definition at line 363 of file Adaptive_Huffman.H.
Referenced by decode_bit(), distinct_symbols(), frequency(), has_pending_symbol(), reset(), and symbols_processed().