44 :
Base(), maxCodeLength(max_code_length)
47 "Code length cannot surpass its underlying container");
58std::unique_ptr<Huffman::Node>
63 while (
trees.size() > 1) {
70 Node* parent =
new Node(left, right);
78 return std::unique_ptr<Node>(root);
101 Code right_code = current_code;
102 right_code.
code = (right_code.
code << 1) + 1;
106 Code left_code = current_code;
107 left_code.
code = left_code.
code << 1;
Node for the Huffman tree.
bool isLeaf() const
Determine if the node is a leaf node by checking if it does not have sub-trees.
uint64_t getValue() const
Get the leaf's value.
const Node * getRightSubTree() const
const Node * getLeftSubTree() const
std::map< uint64_t, Code > valueToCode
Table containing the codewords and their respective lengths.
void sample(uint64_t value, uint64_t frequency)
Inserts the value-frequency pair in the tree.
Code encode(const uint64_t val) const override
The function responsible for the generation of the alternative value.
void generateCodes(const Node *node, const Code ¤t_code)
Recursive function that generates the huffman codes based on the tree provided.
void generateCodeMaps()
Generation of the code maps.
const unsigned maxCodeLength
Maximum number of bits in a codeword.
uint64_t decode(const uint64_t code) const override
Decode a value.
std::map< uint64_t, uint64_t > codeToValue
std::unique_ptr< Node > buildTree()
Build a Huffman tree using the values and their respective frequencies, which have been informed thro...
Huffman(uint64_t max_code_length)
std::priority_queue< Node *, std::vector< Node * >, NodeComparator > trees
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
unsigned length
Number of bits in the code.
uint64_t code
Only the LSB of the code are relevant.