Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
adaptive_huffman_demo Namespace Reference

Classes

struct  Display_Node
 One node of a reconstructed display tree. More...
 
struct  Frame
 One verified encoding event, plus the tree after the event. More...
 
struct  Snapshot
 A complete tree for one externally observable encoder state. More...
 

Functions

std::string byte_label (const unsigned char byte)
 Return an unambiguous, terminal-safe label for a byte.
 
std::string next_code (const Aleph::Adaptive_Huffman_Encoder &encoder, const unsigned char byte)
 Probe a byte's code without changing the source encoder.
 
void insert_code (Snapshot &tree, const std::string &code, const int symbol, const std::uint64_t weight)
 Insert a code into the display trie and accumulate its frequency.
 
void position_nodes (Snapshot &tree, const int node, const size_t depth, size_t &next_leaf)
 Assign inorder leaf positions and center parents over children.
 
Snapshot snapshot (const Aleph::Adaptive_Huffman_Encoder &encoder)
 Reconstruct and validate the tree using public encoder operations.
 
Aleph::Array< Frame > trace (const std::string_view input)
 Record an actual online round trip, starting with the empty model.
 
void print_tree (std::ostream &out, const Snapshot &tree, const int node=0, const std::string &indent=" ", const std::string &edge="")
 Print a byte-labelled, edge-labelled tree using portable ASCII.
 

Function Documentation

◆ byte_label()

std::string adaptive_huffman_demo::byte_label ( const unsigned char  byte)
inline

Return an unambiguous, terminal-safe label for a byte.

Parameters
byteByte to describe.
Returns
Printable ASCII, a control name, or a hexadecimal byte value.

Definition at line 51 of file adaptive_huffman_demo_support.H.

References Aleph::and, and byte_label().

Referenced by byte_label(), and print_tree().

◆ insert_code()

void adaptive_huffman_demo::insert_code ( Snapshot &  tree,
const std::string &  code,
const int  symbol,
const std::uint64_t  weight 
)
inline

Insert a code into the display trie and accumulate its frequency.

Parameters
treeDestination display tree.
codeActual root-to-leaf code.
symbolByte value or -1 for NYT.
weightCurrent symbol frequency.

Definition at line 110 of file adaptive_huffman_demo_support.H.

References adaptive_huffman_demo::Display_Node::code, Aleph::code(), and adaptive_huffman_demo::Snapshot::nodes.

Referenced by snapshot().

◆ next_code()

std::string adaptive_huffman_demo::next_code ( const Aleph::Adaptive_Huffman_Encoder &  encoder,
const unsigned char  byte 
)
inline

Probe a byte's code without changing the source encoder.

Parameters
encoderState immediately before the proposed byte.
byteByte to probe.
Returns
Actual transmitted bits, including a literal for an unseen byte.

Definition at line 76 of file adaptive_huffman_demo_support.H.

References Aleph::bits(), and Aleph::copy().

Referenced by snapshot().

◆ position_nodes()

void adaptive_huffman_demo::position_nodes ( Snapshot &  tree,
const int  node,
const size_t  depth,
size_t &  next_leaf 
)
inline

Assign inorder leaf positions and center parents over children.

Parameters
treeTree to lay out.
nodeCurrent node index.
depthCurrent depth below the root.
next_leafCounter of already positioned leaves.

Definition at line 139 of file adaptive_huffman_demo_support.H.

References adaptive_huffman_demo::Snapshot::depth, adaptive_huffman_demo::Snapshot::nodes, and position_nodes().

Referenced by position_nodes(), and snapshot().

◆ print_tree()

void adaptive_huffman_demo::print_tree ( std::ostream &  out,
const Snapshot &  tree,
const int  node = 0,
const std::string &  indent = "  ",
const std::string &  edge = "" 
)
inline

Print a byte-labelled, edge-labelled tree using portable ASCII.

Parameters
outDestination stream.
treeSnapshot to render.
nodeCurrent node index.
indentAncestor branch prefix.
edgeEmpty at the root, otherwise the incoming edge decoration.

Definition at line 276 of file adaptive_huffman_demo_support.H.

References byte_label(), adaptive_huffman_demo::Snapshot::nodes, out, and print_tree().

Referenced by print_tree().

◆ snapshot()

Snapshot adaptive_huffman_demo::snapshot ( const Aleph::Adaptive_Huffman_Encoder &  encoder)
inline

Reconstruct and validate the tree using public encoder operations.

Parameters
encoderSource encoder; it is never modified.
Returns
Tree with exact codes, frequencies and drawing coordinates.
Exceptions
std::logic_errorif the public codes do not form a full tree.

Definition at line 162 of file adaptive_huffman_demo_support.H.

References ah_logic_error_if, ah_logic_error_unless, Aleph::and, Aleph::code(), Aleph::count(), Aleph::Adaptive_Huffman_Encoder::frequency(), insert_code(), adaptive_huffman_demo::Snapshot::leaf_count, next_code(), adaptive_huffman_demo::Snapshot::nodes, position_nodes(), Aleph::Adaptive_Huffman_Encoder::symbols_processed(), and value.

Referenced by trace().

◆ trace()

Aleph::Array< Frame > adaptive_huffman_demo::trace ( const std::string_view  input)
inline