38#include <gtest/gtest.h>
57 buf.reserve(s.size() + 1);
58 buf.insert(buf.end(), s.begin(), s.end());
73 const string input =
"hello world\nthis\tis a test\n";
79 encoder.read_input(buf.data(),
true);
80 encoder.encode(buf.data(), bits);
93 const string input =
"A";
110 const string input =
"a b\nc\tdd\n";
123 istringstream
in(
out.str());
140 const string input =
"aba";
147 encoder.encode(buf.data(), bits);
163 const string alphabet =
"abcde fghij\n\t";
170 input.reserve(
static_cast<size_t>(len));
171 for (
int i = 0; i < len; ++i)
180 encoder.encode(buf.data(), bits);
Huffman coding for data compression.
Node for binary search tree.
Contiguous array of bits.
void push(const unsigned int value)
Inserts the value at the end of the array.
constexpr size_t size() const noexcept
Returns the dimension of the bit array.
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 set_end_of_stream(const std::string &str)
Defines the end-of-stream symbol.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
bool areEquivalents(Node *t1, Node *t2, Equal &op) noexcept
Return true if trees are equivalents.
Utility functions for binary tree operations.