mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ng_region: clean up and modernise
This commit is contained in:
parent
ca22edc9d3
commit
699ab4190a
@ -70,9 +70,9 @@ using namespace std;
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
typedef ue2::unordered_set<NFAEdge> BackEdgeSet;
|
||||
typedef boost::filtered_graph<NGHolder, bad_edge_filter<BackEdgeSet>>
|
||||
AcyclicGraph;
|
||||
using BackEdgeSet = unordered_set<NFAEdge>;
|
||||
using AcyclicGraph =
|
||||
boost::filtered_graph<NGHolder, bad_edge_filter<BackEdgeSet>>;
|
||||
|
||||
namespace {
|
||||
struct exit_info {
|
||||
@ -85,8 +85,8 @@ struct exit_info {
|
||||
|
||||
static
|
||||
void checkAndAddExitCandidate(const AcyclicGraph &g,
|
||||
const ue2::unordered_set<NFAVertex> &r,
|
||||
NFAVertex v, vector<exit_info> &exits) {
|
||||
const unordered_set<NFAVertex> &r, NFAVertex v,
|
||||
vector<exit_info> &exits) {
|
||||
exit_info v_exit(v);
|
||||
auto &open = v_exit.open;
|
||||
|
||||
@ -104,7 +104,7 @@ void checkAndAddExitCandidate(const AcyclicGraph &g,
|
||||
}
|
||||
|
||||
static
|
||||
void findExits(const AcyclicGraph &g, const ue2::unordered_set<NFAVertex> &r,
|
||||
void findExits(const AcyclicGraph &g, const unordered_set<NFAVertex> &r,
|
||||
vector<exit_info> &exits) {
|
||||
exits.clear();
|
||||
for (auto v : r) {
|
||||
@ -113,7 +113,7 @@ void findExits(const AcyclicGraph &g, const ue2::unordered_set<NFAVertex> &r,
|
||||
}
|
||||
|
||||
static
|
||||
void refineExits(const AcyclicGraph &g, const ue2::unordered_set<NFAVertex> &r,
|
||||
void refineExits(const AcyclicGraph &g, const unordered_set<NFAVertex> &r,
|
||||
NFAVertex new_v, vector<exit_info> &exits) {
|
||||
/* new_v is no long an open edge */
|
||||
for (auto &exit : exits) {
|
||||
@ -121,8 +121,7 @@ void refineExits(const AcyclicGraph &g, const ue2::unordered_set<NFAVertex> &r,
|
||||
}
|
||||
|
||||
/* no open edges: no longer an exit */
|
||||
exits.erase(
|
||||
remove_if(exits.begin(), exits.end(),
|
||||
exits.erase(remove_if(exits.begin(), exits.end(),
|
||||
[&](const exit_info &exit) { return exit.open.empty(); }),
|
||||
exits.end());
|
||||
|
||||
@ -162,8 +161,8 @@ bool exitValid(UNUSED const AcyclicGraph &g, const vector<exit_info> &exits,
|
||||
}
|
||||
|
||||
static
|
||||
void setRegion(const ue2::unordered_set<NFAVertex> &r, u32 rid,
|
||||
ue2::unordered_map<NFAVertex, u32> ®ions) {
|
||||
void setRegion(const unordered_set<NFAVertex> &r, u32 rid,
|
||||
unordered_map<NFAVertex, u32> ®ions) {
|
||||
for (auto v : r) {
|
||||
regions[v] = rid;
|
||||
}
|
||||
@ -173,34 +172,34 @@ static
|
||||
void buildInitialCandidate(const AcyclicGraph &g,
|
||||
vector<NFAVertex>::const_reverse_iterator &it,
|
||||
const vector<NFAVertex>::const_reverse_iterator &ite,
|
||||
ue2::unordered_set<NFAVertex> *candidate,
|
||||
unordered_set<NFAVertex> &candidate,
|
||||
/* in exits of prev region;
|
||||
* out exits from candidate */
|
||||
vector<exit_info> &exits,
|
||||
flat_set<NFAVertex> *open_jumps) {
|
||||
flat_set<NFAVertex> &open_jumps) {
|
||||
if (it == ite) {
|
||||
candidate->clear();
|
||||
candidate.clear();
|
||||
exits.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (exits.empty()) {
|
||||
DEBUG_PRINTF("odd\n");
|
||||
candidate->clear();
|
||||
candidate.clear();
|
||||
DEBUG_PRINTF("adding %zu to initial\n", g[*it].index);
|
||||
candidate->insert(*it);
|
||||
open_jumps->erase(*it);
|
||||
checkAndAddExitCandidate(g, *candidate, *it, exits);
|
||||
candidate.insert(*it);
|
||||
open_jumps.erase(*it);
|
||||
checkAndAddExitCandidate(g, candidate, *it, exits);
|
||||
++it;
|
||||
return;
|
||||
}
|
||||
|
||||
auto enters = exits.front().open; // copy
|
||||
candidate->clear();
|
||||
candidate.clear();
|
||||
|
||||
for (; it != ite; ++it) {
|
||||
DEBUG_PRINTF("adding %zu to initial\n", g[*it].index);
|
||||
candidate->insert(*it);
|
||||
candidate.insert(*it);
|
||||
if (contains(enters, *it)) {
|
||||
break;
|
||||
}
|
||||
@ -208,24 +207,24 @@ void buildInitialCandidate(const AcyclicGraph &g,
|
||||
|
||||
if (it != ite) {
|
||||
enters.erase(*it);
|
||||
*open_jumps = move(enters);
|
||||
DEBUG_PRINTF("oj size = %zu\n", open_jumps->size());
|
||||
open_jumps = move(enters);
|
||||
DEBUG_PRINTF("oj size = %zu\n", open_jumps.size());
|
||||
++it;
|
||||
} else {
|
||||
open_jumps->clear();
|
||||
open_jumps.clear();
|
||||
}
|
||||
|
||||
findExits(g, *candidate, exits);
|
||||
findExits(g, candidate, exits);
|
||||
}
|
||||
|
||||
static
|
||||
void findDagLeaders(const NGHolder &h, const AcyclicGraph &g,
|
||||
const vector<NFAVertex> &topo,
|
||||
ue2::unordered_map<NFAVertex, u32> ®ions) {
|
||||
unordered_map<NFAVertex, u32> ®ions) {
|
||||
assert(!topo.empty());
|
||||
u32 curr_id = 0;
|
||||
vector<NFAVertex>::const_reverse_iterator t_it = topo.rbegin();
|
||||
ue2::unordered_set<NFAVertex> candidate;
|
||||
auto t_it = topo.rbegin();
|
||||
unordered_set<NFAVertex> candidate;
|
||||
flat_set<NFAVertex> open_jumps;
|
||||
DEBUG_PRINTF("adding %zu to current\n", g[*t_it].index);
|
||||
assert(t_it != topo.rend());
|
||||
@ -251,8 +250,8 @@ void findDagLeaders(const NGHolder &h, const AcyclicGraph &g,
|
||||
DEBUG_PRINTF("setting region %u\n", curr_id);
|
||||
}
|
||||
setRegion(candidate, curr_id++, regions);
|
||||
buildInitialCandidate(g, t_it, topo.rend(), &candidate, exits,
|
||||
&open_jumps);
|
||||
buildInitialCandidate(g, t_it, topo.rend(), candidate, exits,
|
||||
open_jumps);
|
||||
} else {
|
||||
NFAVertex curr = *t_it;
|
||||
DEBUG_PRINTF("adding %zu to current\n", g[curr].index);
|
||||
@ -271,7 +270,7 @@ void findDagLeaders(const NGHolder &h, const AcyclicGraph &g,
|
||||
static
|
||||
void mergeUnderBackEdges(const NGHolder &g, const vector<NFAVertex> &topo,
|
||||
const BackEdgeSet &backEdges,
|
||||
ue2::unordered_map<NFAVertex, u32> ®ions) {
|
||||
unordered_map<NFAVertex, u32> ®ions) {
|
||||
for (const auto &e : backEdges) {
|
||||
NFAVertex u = source(e, g);
|
||||
NFAVertex v = target(e, g);
|
||||
@ -341,7 +340,7 @@ void reorderSpecials(const NGHolder &w, const AcyclicGraph &acyclic_g,
|
||||
|
||||
static
|
||||
void liftSinks(const AcyclicGraph &acyclic_g, vector<NFAVertex> &topoOrder) {
|
||||
ue2::unordered_set<NFAVertex> sinks;
|
||||
unordered_set<NFAVertex> sinks;
|
||||
for (auto v : vertices_range(acyclic_g)) {
|
||||
if (is_special(v, acyclic_g)) {
|
||||
continue;
|
||||
@ -386,7 +385,7 @@ void liftSinks(const AcyclicGraph &acyclic_g, vector<NFAVertex> &topoOrder) {
|
||||
}
|
||||
NFAVertex s = *ri;
|
||||
DEBUG_PRINTF("handling sink %zu\n", acyclic_g[s].index);
|
||||
ue2::unordered_set<NFAVertex> parents;
|
||||
unordered_set<NFAVertex> parents;
|
||||
for (const auto &e : in_edges_range(s, acyclic_g)) {
|
||||
parents.insert(NFAVertex(source(e, acyclic_g)));
|
||||
}
|
||||
@ -437,7 +436,7 @@ vector<NFAVertex> buildTopoOrder(const NGHolder &w,
|
||||
return topoOrder;
|
||||
}
|
||||
|
||||
ue2::unordered_map<NFAVertex, u32> assignRegions(const NGHolder &g) {
|
||||
unordered_map<NFAVertex, u32> assignRegions(const NGHolder &g) {
|
||||
assert(hasCorrectlyNumberedVertices(g));
|
||||
const u32 numVertices = num_vertices(g);
|
||||
DEBUG_PRINTF("assigning regions for %u vertices in holder\n", numVertices);
|
||||
@ -459,7 +458,7 @@ ue2::unordered_map<NFAVertex, u32> assignRegions(const NGHolder &g) {
|
||||
vector<NFAVertex> topoOrder = buildTopoOrder(g, acyclic_g, colours);
|
||||
|
||||
// Everybody starts in region 0.
|
||||
ue2::unordered_map<NFAVertex, u32> regions;
|
||||
unordered_map<NFAVertex, u32> regions;
|
||||
regions.reserve(numVertices);
|
||||
for (auto v : vertices_range(g)) {
|
||||
regions.emplace(v, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user