6 namespace tdc {
namespace esp {
8 std::vector<size_t> first_child;
11 for (
size_t i = 0; i < first_child.size(); i++) {
15 std::vector<size_t> next_child;
18 for (
size_t i = 0; i < next_child.size(); i++) {
22 auto append = [&](
size_t i,
size_t node) {
24 if (first_child[i] == i) {
25 first_child[i] = node;
27 auto old_next = first_child[i];
28 first_child[i] = node;
29 next_child[node] = old_next;
33 auto for_all = [&](
size_t i,
auto f) {
34 size_t l = first_child[i];
38 if (next_child[l] != l) {
48 for (
size_t i = 0; i < slp.
rules.size(); i++) {
49 auto j = slp.
rules.size() - i - 1;
52 auto left_child = slp.
rules[j][0];
53 append(left_child, node);
57 std::vector<size_t> rename;
58 rename.reserve(slp.
rules.size());
59 rename.resize(slp.
rules.size());
61 std::queue<size_t> queue;
62 for (
size_t i = 0; i < 256; i++) {
67 while (!queue.empty()) {
68 auto elem = queue.front();
70 for_all(elem, [&](
size_t child) {
74 auto new_value = counter++;
77 DCHECK_EQ(elem, new_value);
82 rename[original_idx] = new_idx;
89 auto discard = std::move(first_child);
90 discard = std::move(next_child);
94 std::vector<std::array<size_t, 2>> renamed_slp;
95 renamed_slp.reserve(slp.
rules.size());
96 renamed_slp.resize(slp.
rules.size());
98 for (
size_t i = 0; i < renamed_slp.size(); i++) {
99 renamed_slp[rename[i]] = slp.
rules[i];
100 for (
auto& e : renamed_slp[rename[i]]) {
107 slp.
rules = std::move(renamed_slp);
Contains the text compression and encoding framework.
std::vector< std::array< size_t, 2 > > rules
size_t GRAMMAR_PD_ELLIDED_PREFIX
void slp_dep_sort(SLP &slp)