29#ifndef __MEM_CACHE_COMPRESSORS_ENCODERS_HUFFMAN_HH__
30#define __MEM_CACHE_COMPRESSORS_ENCODERS_HUFFMAN_HH__
57 Huffman(uint64_t max_code_length);
66 void sample(uint64_t value, uint64_t frequency);
72 uint64_t
decode(
const uint64_t code)
const override;
93 Node(uint64_t value, uint64_t frequency)
Node for the Huffman tree.
uint64_t getFrequency() const
Getter for the frequency counter.
const uint64_t _value
Value represented by this node, if this is a leaf node.
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.
Node(Node *left, Node *right)
Initialize node as an internal node.
std::unique_ptr< Node > _right
The right tree.
Node(uint64_t value, uint64_t frequency)
Initialize node as a leaf node.
const Node * getRightSubTree() const
std::unique_ptr< Node > _left
The left tree.
const Node * getLeftSubTree() const
const uint64_t _frequency
Frequency of the value represented by this node.
This encoder builds a Huffman tree using the frequency of each value to be encoded.
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
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Entries are not inserted directly into the tree.
bool operator()(const Node *lhs, const Node *rhs) const