137 const std::string & str = p->
get_key();
210 return is_leaf(p) ? p->get_key() :
"";
219 input >> p->get_key();
239 <<
"Huffman tree has not been generated";
272 <<
"Huffman tree has not been generated";
282 <<
"Huffman tree has not been generated";
310 BinNode <std::string> * bin_node =
new BinNode <std::string>;
338 const std::string str = std::to_string(
new_freq);
341 freq_node->
get_key().first = str;
395 <<
"Huffman tree has not been generated";
418 std::string msg =
"Frequency for symbol " + str +
" has already set";
436 output << str.size() <<
" ";
437 for (
unsigned char c : str)
438 output <<
static_cast<unsigned int>(c) <<
" ";
450 for (
size_t i = 0; i < len; ++i)
452 unsigned int byte = 0;
456 str[i] =
static_cast<char>(
static_cast<unsigned char>(byte));
590 <<
"End symbol is already present as a normal symbol";
615 <<
"Huffman tree has not been generated";
618 <<
"End symbol has not been configured";
646 <<
"Huffman tree has not been generated";
649 <<
"End symbol has not been configured";
692 <<
"Huffman tree has not been generated";
718 <<
"Invalid bits sequence";
722 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
Actualiza prioridad de un nodo contenido en el heap.
bool is_empty() const noexcept
Node * getMin()
Elimina del heap el nodo de menor prioridad.
Node * getMin_ne() noexcept
Node * insert(Node *p) noexcept
Inserta un nodo en un heap.
const size_t & size() const noexcept
size_t size() const noexcept
Count the number of elements of the list.
BinNode< std::string > * root
void decode(BitArray &bit_stream, std::ostream &output)
Decode a bit stream.
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 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()
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
BinNode< std::string > * root
void clear_build_state() noexcept
void save_tree(std::ostream &output)
Save a Huffman tree into a stream.
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.
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.
void save_tree_in_array_of_chars(const std::string &array_name, std::ostream &output)
Generate C/C++ array declarations for a Huffman 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.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
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
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Main namespace for Aleph-w library functions.
BinNode< std::pair< std::string, size_t > > Freq_Node
BinHeap< size_t > Huffman_Heap
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
DynList< T > maps(const C &c, Op op)
Classic map operation.
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.