11 namespace tdc {
namespace esp {
12 template<
typename ipd_t>
19 size_t slp_counter = 256;
20 size_t prev_slp_counter = 0;
22 std::unique_ptr<Round<ipd_t>> round;
26 auto phase = with_env([&](
auto& env) {
35 round->string.width(
bits_for(256 - 1));
36 round->string.reserve(input.size(),
bits_for(256 - 1));
37 for (
auto c : input) {
38 round->string.push_back(c);
40 auto discard = std::move(input);
43 for(
size_t n = 0;; n++) {
44 auto phase = with_env([&](
auto& env) {
56 behavior_metablocks_maximimze_repeating,
57 behavior_landmarks_tie_to_right,
65 ctx.debug.last_round(0,
true);
69 root_node = in[0] + prev_slp_counter;
70 ctx.debug.last_round(root_node,
false);
75 size_t new_layer_width =
bits_for(in.size() - 1);
76 new_layer.
width(new_layer_width);
77 new_layer.
reserve(in.size() / 2 + 1, new_layer_width);
81 const auto& v = ctx.adjusted_blocks();
83 ctx.debug.slice_symbol_map_start();
87 auto slice = s.slice(0, e.len);
89 auto rule_name = r.gr.add(slice) - (r.gr.initial_counter() - 1);
91 ctx.debug.slice_symbol_map(slice, rule_name);
96 DCHECK_EQ(old_cap, new_cap);
103 DCHECK_EQ(r.string.size(), 0);
104 DCHECK_EQ(r.string.capacity(), 0);
110 size_t old_slp_size = slp.
rules.size();
111 size_t additional_slp_size = r.gr.rules_count();
112 size_t new_slp_size = old_slp_size + additional_slp_size;
114 slp.
rules.reserve(new_slp_size);
115 slp.
rules.resize(new_slp_size);
117 auto& rv = slp.
rules;
119 r.gr.for_all([&](
const auto& k,
const auto& val_) {
120 const auto& val = val_ - r.gr.initial_counter();
121 const auto& key = k.as_view();
123 size_t store_idx = slp_counter + val - 256;
124 rv[store_idx][0] = key[0] + prev_slp_counter;
125 rv[store_idx][1] = key[1] + prev_slp_counter;
128 prev_slp_counter = slp_counter;
129 slp_counter += additional_slp_size;
133 auto round_ipd_stats = r.gr.stats();
134 ipd_stats.ext_size2_total += round_ipd_stats.ext_size2_total;
135 ipd_stats.ext_size3_total += round_ipd_stats.ext_size3_total;
136 ipd_stats.ext_size3_unique += round_ipd_stats.ext_size3_unique;
137 ipd_stats.int_size2_total += round_ipd_stats.int_size2_total;
138 ipd_stats.int_size2_unique += round_ipd_stats.int_size2_unique;
147 std::move(new_layer),
151 round = std::make_unique<Round<ipd_t>>(std::move(tmp));
153 phase.log_stat(
"SLP size", slp.
rules.size());
154 phase.log_stat(
"ext_size2_total", round_ipd_stats.ext_size2_total);
155 phase.log_stat(
"ext_size3_total", round_ipd_stats.ext_size3_total);
156 phase.log_stat(
"ext_size3_unique", round_ipd_stats.ext_size3_unique);
157 phase.log_stat(
"int_size2_total", round_ipd_stats.int_size2_total);
158 phase.log_stat(
"int_size2_unique", round_ipd_stats.int_size2_unique);
BitPackingVectorSlice< dynamic_t > in_t
Contains the text compression and encoding framework.
constexpr uint_fast8_t bits_for(size_t n)
Computes the number of bits required to store the given integer value.
size_t rules_count() const
std::vector< std::array< size_t, 2 > > rules
A vector over arbitrary unsigned integer types.
void push_back(const value_type &val)
Provides access to runtime and memory measurement in statistics phases.
void init(size_t number, const X &string, size_t alphabet_size)
size_type capacity() const
void reserve(size_type n)
SLP generate_grammar(T &&s)