diff --git a/src/nfagraph/ng_literal_decorated.cpp b/src/nfagraph/ng_literal_decorated.cpp index 652fd14a..02b25a73 100644 --- a/src/nfagraph/ng_literal_decorated.cpp +++ b/src/nfagraph/ng_literal_decorated.cpp @@ -67,6 +67,7 @@ static bool findPaths(const NGHolder &g, vector &paths) { vector order = getTopoOrdering(g); + vector read_count(num_vertices(g)); vector> built(num_vertices(g)); for (auto it = order.rbegin(); it != order.rend(); ++it) { @@ -74,6 +75,11 @@ bool findPaths(const NGHolder &g, vector &paths) { auto &out = built[g[v].index]; assert(out.empty()); + read_count[g[v].index] = out_degree(v, g); + + DEBUG_PRINTF("setting read_count to %zu for %u\n", + read_count[g[v].index], g[v].index); + if (v == g.start || v == g.startDs) { out.push_back({v}); continue; @@ -94,6 +100,9 @@ bool findPaths(const NGHolder &g, vector &paths) { continue; } + assert(!built[g[u].index].empty()); + assert(read_count[g[u].index]); + for (const auto &p : built[g[u].index]) { out.push_back(p); out.back().push_back(v); @@ -105,6 +114,13 @@ bool findPaths(const NGHolder &g, vector &paths) { return false; } } + + read_count[g[u].index]--; + if (!read_count[g[u].index]) { + DEBUG_PRINTF("clearing %u as finished reading\n", g[u].index); + built[g[u].index].clear(); + built[g[u].index].shrink_to_fit(); + } } } diff --git a/src/nfagraph/ng_small_literal_set.cpp b/src/nfagraph/ng_small_literal_set.cpp index 89cb0ff8..b5867bb9 100644 --- a/src/nfagraph/ng_small_literal_set.cpp +++ b/src/nfagraph/ng_small_literal_set.cpp @@ -118,10 +118,15 @@ bool findLiterals(const NGHolder &g, vector order = getTopoOrdering(g); vector> built(num_vertices(g)); + vector read_count(num_vertices(g)); for (auto it = order.rbegin(); it != order.rend(); ++it) { NFAVertex v = *it; set &out = built[g[v].index]; + read_count[g[v].index] = out_degree(v, g); + + DEBUG_PRINTF("setting read_count to %zu for %u\n", + read_count[g[v].index], g[v].index); assert(out.empty()); if (v == g.start) { @@ -149,7 +154,10 @@ bool findLiterals(const NGHolder &g, } set &in = built[g[u].index]; + DEBUG_PRINTF("getting from %u (%zu reads to go)\n", + g[u].index, read_count[g[u].index]); assert(!in.empty()); + assert(read_count[g[u].index]); for (const sls_literal &lit : in) { if (accept) { @@ -171,10 +179,18 @@ bool findLiterals(const NGHolder &g, out.insert(lit.append((u8)c, nocase)); if (out.size() + literals->size() > MAX_LITERAL_SET_SIZE) { + DEBUG_PRINTF("too big %zu + %zu\n", out.size(), + literals->size()); return false; } } } + + read_count[g[u].index]--; + if (!read_count[g[u].index]) { + DEBUG_PRINTF("clearing %u as finished reading\n", g[u].index); + in.clear(); + } } } @@ -206,6 +222,8 @@ bool handleSmallLiteralSets(RoseBuild &rose, const NGHolder &g, return false; } + DEBUG_PRINTF("looking for literals\n"); + map> literals; if (!findLiterals(g, &literals)) { DEBUG_PRINTF(":(\n");