130 const std::string &str = p->
get_key();
207 return is_leaf(p) ? p->get_key() :
"";
216 input >> p->get_key();
327 const std::string str = std::to_string(
new_freq);
330 freq_node->
get_key().first = str;
397 void set_freq(
const std::string &str,
const size_t &freq)
406 std::string msg =
"Frequency for symbol " + str +
" has already set";
423 output << str.size() <<
" ";
424 for (
unsigned char c : str)
425 output <<
static_cast<unsigned int>(c) <<
" ";
437 for (
size_t i = 0; i < len; ++i)
439 unsigned int byte = 0;
443 str[i] =
static_cast<char>(
static_cast<unsigned char>(byte));
576 <<
"End symbol is already present as a normal symbol";
700 const std::string &symbol = p->
get_key();
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error()
Throws std::domain_error unconditionally.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
WeightedDigraph::Node Node
Space-efficient bit array implementation.
Node for binary search tree.
Contiguous array of bits.
void pop()
Removes the last bit of the array.
void load(std::istream &input)
Loads an array of bits from a file.
void push(const unsigned int value)
Inserts the value at the end of the array.
Pair * search(const Key &key) const noexcept
Collect all keys.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Data & find(const Key &key)
Find the value associated with key.
void empty()
remove all elements from the set
void update(Node *p) noexcept
Updates the priority of a node contained in the heap.
bool is_empty() const noexcept
Node * getMin()
Removes the node with the lowest priority from the heap.
Node * getMin_ne() noexcept
Node * insert(Node *p) noexcept
Inserts a node into a heap.
const size_t & size() const noexcept
BinNode< std::string > * root
Huffman_Decoder_Engine(BinNode< std::string > *p, const std::string &end)
Decoder constructor.
BinNode< std::string > *& get_root()
Returns the root of the Huffman decoding tree.
void decode(const BitArray &bit_stream, std::ostream &output) const
Decode a bit stream.
void insert_end_symbol_node(const std::string &str)
Freq_Node *& get_freq_root()
Returns the root of the frequency tree.
static void save_leaf_keys_in_prefix(BinNode< std::string > *p, std::ostream &output)
void update_freq(const std::string &str)
void build_encoding_map()
void save_tree_in_array_of_chars(const std::string &array_name, std::ostream &output) const
Generate C/C++ array declarations for a Huffman tree.
void save_tree(std::ostream &output) const
Save a Huffman tree into a stream.
size_t encode(char *input, BitArray &bit_stream)
Encode the input text.
static std::string load_string_from_bytes(std::istream &input)
void load_tree(std::istream &input)
Load and build a binary tree from a stream.
static const size_t Max_Token_Size
void clear_build_state() noexcept
BinNode< std::string > *& get_root()
Returns the root of the Huffman decoding tree.
void set_freq(const std::string &str, const size_t &freq)
Define the frequency of a symbol.
BinNode< std::string > * root_
static void save_string_as_bytes(const std::string &str, std::ostream &output)
void read_input(char *input, const bool &with_freqs=false)
Read a NUL-terminated character std::string, count frequencies and build the prefix tree.
static void load_leaf_keys_in_prefix(BinNode< std::string > *p, std::istream &input)
void read_input(std::istream &input, const bool &with_freqs=false)
Read a stream, count frequencies and build the prefix tree.
bool test_end(const std::string &str) const
void set_end_of_stream(const std::string &str)
Defines the end-of-stream symbol.
~Huffman_Encoder_Engine()
Destructor - frees all allocated memory.
Huffman_Encoder_Engine()
Encoder constructor.
static void append_code(BitArray &bit_stream, const BitArray &symbol_code)
void build_prefix_encoding(BinNode< std::string > *p, BitArray &array)
const std::string & get_end_of_stream() const noexcept
Return the configured end-of-stream symbol.
size_t encode(std::istream &input, BitArray &bit_stream)
Encode the input text from a stream.
BinNode< std::string > * generate_huffman_tree(const bool &with_freqs=false)
Generate the Huffman prefix tree.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void tree_to_bits(Node *root, BitArray &array)
Compute a bit code for the binary tree.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
Main namespace for Aleph-w library functions.
BinNode< std::pair< std::string, size_t > > Freq_Node
BinHeap< size_t > Huffman_Heap
and
Check uniqueness with explicit hash + equality functors.
DynMapTree< std::string, BitArray, Treap_Vtl > Code_Map
static void increase_freq(Huffman_Node *huffman_node) noexcept
static void prefix(Node *root, DynList< Node * > &acc)
static const size_t & get_freq(Huffman_Node *huffman_node) noexcept
static bool is_leaf(BinNode< std::string > *p) noexcept
static void set_freq(Huffman_Node *huffman_node, const size_t &freq) noexcept
Node heap without virtual destructor.
std::string operator()(BinNode< std::string > *p) const noexcept
void operator()(BinNode< std::string > *p, std::istream &input) const noexcept
Huffman_Node(BinNode< std::string > *node)
BinNode< std::string > * bin_node
Binary heap implementation using tree structure.
Utility functions for binary tree operations.
Dynamic key-value map based on balanced binary search trees.
Treap: randomized BST combining tree and heap properties.