22 std::vector<factorid_t> first_child;
23 std::vector<factorid_t> left_sibling;
24 std::vector<factorid_t> right_sibling;
25 std::vector<uliteral_t> literal;
29 Meta m(
"lz78trie",
"ternary",
"Lempel-Ziv 78 Ternary Trie");
39 first_child.reserve(reserve);
40 left_sibling.reserve(reserve);
41 right_sibling.reserve(reserve);
42 literal.reserve(reserve);
48 size_t m_specialresizes = 0;
58 StatPhase::log(
"load ratio", first_child.size()*100/first_child.capacity());
81 right_sibling.clear();
86 auto parent = parent_w.
id();
90 DCHECK_LT(parent,
size());
93 if(first_child[parent] ==
undef_id) {
94 first_child[parent] = newleaf_id;
98 if(c < literal[node]) {
99 if (left_sibling[node] ==
undef_id) {
100 left_sibling[node] = newleaf_id;
104 node = left_sibling[node];
106 else if (c > literal[node]) {
107 if (right_sibling[node] ==
undef_id) {
108 right_sibling[node] = newleaf_id;
112 node = right_sibling[node];
115 return node_t(node,
false);
120 if(first_child.capacity() == first_child.size()) {
122 if(newbound < first_child.size()*2 ) {
123 first_child.reserve (newbound);
124 left_sibling.reserve (newbound);
125 right_sibling.reserve (newbound);
126 literal.reserve (newbound);
134 literal.push_back(c);
139 return first_child.size();
Contains the text compression and encoding framework.
uint8_t uliteral_t
Type to represent signed single literals.
TernaryTrie & operator=(TernaryTrie &&other)=default
node_t find_or_insert(const node_t &parent_w, uliteral_t c)
IF_STATS(size_t m_resizes=0;size_t m_specialresizes=0;) IF_STATS(MoveGuard m_guard
Env & env()
Provides access to the environment that the algorithm works in.
Default return type of find_or_insert.
node_t get_rootnode(uliteral_t c) const
TernaryTrie(Env &&env, const size_t n, const size_t &remaining_characters, factorid_t reserve=0)
static void log(const char *key, const T &value)
Logs a user statistic for the current phase.
uint32_t factorid_t
Type for the factor indices, bounded by the number of LZ78 trie nodes.
constexpr factorid_t undef_id
Id that can be used for a non-existing factor.
Local environment for a compression/encoding/decompression call.
node_t add_rootnode(uliteral_t c)
Interface for algorithms.
size_t expected_number_of_remaining_elements(const size_t z) const
LZ78 Trie Implementation based on Julius Pettersson (MIT/Expat License.) and Juha Nieminen's work...