diff --git a/util/ng_find_matches.cpp b/util/ng_find_matches.cpp index 13efa05c..80a06a15 100644 --- a/util/ng_find_matches.cpp +++ b/util/ng_find_matches.cpp @@ -60,8 +60,9 @@ static constexpr size_t STATE_COUNT_MAX = 15000; static vector> gatherSuccessorsByDepth(const NGHolder &g, const NFAVertex &src, u32 depth) { + assert(depth > 0); + vector> result(depth); - flat_set cur, next; // populate current set of successors for (auto v : adjacent_vertices_range(src, g)) { @@ -70,31 +71,28 @@ gatherSuccessorsByDepth(const NGHolder &g, const NFAVertex &src, u32 depth) { continue; } DEBUG_PRINTF("Node %zu depth 1\n", g[v].index); - - cur.insert(v); + result[0].insert(v); } - result[0] = cur; for (u32 d = 1; d < depth; d++) { // collect all successors for all current level vertices - for (auto v : cur) { + const auto &cur = result[d - 1]; + auto &next = result[d]; + for (auto u : cur) { // don't go past special nodes - if (is_special(v, g)) { + if (is_special(u, g)) { continue; } - for (auto succ : adjacent_vertices_range(v, g)) { + for (auto v : adjacent_vertices_range(u, g)) { // ignore self-loops - if (v == succ) { + if (u == v) { continue; } - DEBUG_PRINTF("Node %zu depth %u\n", g[succ].index, d + 1); - next.insert(succ); + DEBUG_PRINTF("Node %zu depth %u\n", g[v].index, d + 1); + next.insert(v); } } - result[d] = next; - next.swap(cur); - next.clear(); } return result; @@ -103,13 +101,12 @@ gatherSuccessorsByDepth(const NGHolder &g, const NFAVertex &src, u32 depth) { // returns all predecessors up to a given depth in a vector of sets, indexed by // zero-based depth from source vertex static -vector> gatherPredecessorsByDepth(const NGHolder &g, - NFAVertex src, u32 depth) { - vector> result(depth); - flat_set cur, next; - +vector> +gatherPredecessorsByDepth(const NGHolder &g, NFAVertex src, u32 depth) { assert(depth > 0); + vector> result(depth); + // populate current set of successors for (auto v : inv_adjacent_vertices_range(src, g)) { // ignore self-loops @@ -117,25 +114,23 @@ vector> gatherPredecessorsByDepth(const NGHolder &g, continue; } DEBUG_PRINTF("Node %zu depth 1\n", g[v].index); - cur.insert(v); + result[0].insert(v); } - result[0] = cur; for (u32 d = 1; d < depth; d++) { // collect all successors for all current level vertices + const auto &cur = result[d - 1]; + auto &next = result[d]; for (auto v : cur) { - for (auto pred : inv_adjacent_vertices_range(v, g)) { + for (auto u : inv_adjacent_vertices_range(v, g)) { // ignore self-loops - if (v == pred) { + if (v == u) { continue; } - DEBUG_PRINTF("Node %zu depth %u\n", g[pred].index, d + 1); - next.insert(pred); + DEBUG_PRINTF("Node %zu depth %u\n", g[u].index, d + 1); + next.insert(u); } } - result[d] = next; - next.swap(cur); - next.clear(); } return result;