mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
allow edge_descriptors to be created from pair<edge_descriptor, bool>
This commit is contained in:
@@ -377,17 +377,14 @@ void resolveEdges(ReportManager &rm, NGWrapper &g, set<NFAEdge> *dead) {
|
||||
add_edge(vv, g.accept, g);
|
||||
g[e].assert_flags = 0;
|
||||
add_edge(u, vv, g[e], g);
|
||||
if (!edge(u, g.acceptEod, g).second) {
|
||||
add_edge(u, g.acceptEod, g[e], g);
|
||||
} else {
|
||||
/* there may already be a different edge from start to eod
|
||||
* if so we need to make it unconditional and alive
|
||||
*/
|
||||
NFAEdge start_eod = edge(u, g.acceptEod, g).first;
|
||||
|
||||
/* there may already be a different edge from start to eod if so
|
||||
* we need to make it unconditional and alive
|
||||
*/
|
||||
if (NFAEdge start_eod = edge(u, g.acceptEod, g)) {
|
||||
g[start_eod].assert_flags = 0;
|
||||
dead->erase(start_eod);
|
||||
|
||||
} else {
|
||||
add_edge(u, g.acceptEod, g[e], g);
|
||||
}
|
||||
dead->insert(e);
|
||||
}
|
||||
@@ -433,17 +430,14 @@ void resolveEdges(ReportManager &rm, NGWrapper &g, set<NFAEdge> *dead) {
|
||||
add_edge(vv, g.accept, g);
|
||||
g[e].assert_flags = 0;
|
||||
add_edge(u, vv, g[e], g);
|
||||
if (!edge(u, g.acceptEod, g).second) {
|
||||
add_edge(u, g.acceptEod, g[e], g);
|
||||
} else {
|
||||
/* there may already be a different edge from start to eod
|
||||
* if so we need to make it unconditional and alive
|
||||
*/
|
||||
NFAEdge start_eod = edge(u, g.acceptEod, g).first;
|
||||
|
||||
/* there may already be a different edge from start to eod if so
|
||||
* we need to make it unconditional and alive
|
||||
*/
|
||||
if (NFAEdge start_eod = edge(u, g.acceptEod, g)) {
|
||||
g[start_eod].assert_flags = 0;
|
||||
dead->erase(start_eod);
|
||||
|
||||
} else {
|
||||
add_edge(u, g.acceptEod, g[e], g);
|
||||
}
|
||||
dead->insert(e);
|
||||
}
|
||||
@@ -496,10 +490,8 @@ void ensureCodePointStart(ReportManager &rm, NGWrapper &g) {
|
||||
* boundaries. Assert resolution handles the badness coming from asserts.
|
||||
* The only other source of trouble is startDs->accept connections.
|
||||
*/
|
||||
bool exists;
|
||||
NFAEdge orig;
|
||||
tie(orig, exists) = edge(g.startDs, g.accept, g);
|
||||
if (g.utf8 && exists) {
|
||||
NFAEdge orig = edge(g.startDs, g.accept, g);
|
||||
if (g.utf8 && orig) {
|
||||
DEBUG_PRINTF("rectifying %u\n", g.reportId);
|
||||
Report ir = rm.getBasicInternalReport(g);
|
||||
ReportID rep = rm.getInternalId(ir);
|
||||
|
@@ -194,9 +194,7 @@ pair<NFAEdge, bool> NFABuilderImpl::addEdge(NFAVertex u, NFAVertex v) {
|
||||
// assert that the edge doesn't already exist
|
||||
assert(edge(u, v, *graph).second == false);
|
||||
|
||||
pair<NFAEdge, bool> e = add_edge(u, v, *graph);
|
||||
assert(e.second);
|
||||
return e;
|
||||
return add_edge(u, v, *graph);
|
||||
}
|
||||
|
||||
void NFABuilderImpl::addEdge(Position startPos, Position endPos) {
|
||||
|
@@ -564,7 +564,7 @@ void mergeClass(vector<unique_ptr<VertexInfo>> &infos, NGHolder &g,
|
||||
pred_info->succ.erase(old_vertex_info);
|
||||
|
||||
// if edge doesn't exist, create it
|
||||
NFAEdge e = add_edge_if_not_present(pred_info->v, new_v, g).first;
|
||||
NFAEdge e = add_edge_if_not_present(pred_info->v, new_v, g);
|
||||
|
||||
// put edge tops, if applicable
|
||||
if (!edgetops.empty()) {
|
||||
@@ -576,7 +576,7 @@ void mergeClass(vector<unique_ptr<VertexInfo>> &infos, NGHolder &g,
|
||||
|
||||
if (new_v_eod) {
|
||||
NFAEdge ee = add_edge_if_not_present(pred_info->v, new_v_eod,
|
||||
g).first;
|
||||
g);
|
||||
|
||||
// put edge tops, if applicable
|
||||
if (!edgetops.empty()) {
|
||||
|
@@ -92,7 +92,7 @@ void addReverseEdges(NGHolder &g, vector<NFAEdge> &reverseEdge,
|
||||
if (it == allEdges.end()) {
|
||||
// No reverse edge, add one.
|
||||
NFAVertex u = source(fwd, g), v = target(fwd, g);
|
||||
NFAEdge rev = add_edge(v, u, g).first;
|
||||
NFAEdge rev = add_edge(v, u, g);
|
||||
it = allEdges.insert(make_pair(make_pair(vidx, uidx), rev)).first;
|
||||
// Add to capacity map.
|
||||
u32 revIndex = g[rev].index;
|
||||
|
@@ -307,10 +307,8 @@ void markForRemoval(const NFAVertex v, VertexInfoMap &infoMap,
|
||||
|
||||
static
|
||||
bool hasInEdgeTops(const NGHolder &g, NFAVertex v) {
|
||||
bool exists;
|
||||
NFAEdge e;
|
||||
tie(e, exists) = edge(g.start, v, g);
|
||||
return exists && !g[e].tops.empty();
|
||||
NFAEdge e = edge(g.start, v, g);
|
||||
return e && !g[e].tops.empty();
|
||||
}
|
||||
|
||||
/** Transform (1), removal of redundant vertices. */
|
||||
@@ -737,11 +735,10 @@ u32 findCyclic(const NGHolder &g, vector<bool> &cyclic) {
|
||||
|
||||
for (auto v : vertices_range(g)) {
|
||||
assert(g[v].index < cyclic.size());
|
||||
bool c = edge(v, v, g).second;
|
||||
if (c) {
|
||||
if (hasSelfLoop(v, g)) {
|
||||
count++;
|
||||
cyclic[g[v].index] = true;
|
||||
}
|
||||
cyclic[g[v].index] = c;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
@@ -1121,7 +1121,7 @@ NFAVertex buildTriggerStates(NGHolder &g, const vector<CharReach> &trigger,
|
||||
g[v].char_reach = cr;
|
||||
add_edge(u, v, g);
|
||||
if (u == g.start) {
|
||||
g[edge(u, v, g).first].tops.insert(top);
|
||||
g[edge(u, v, g)].tops.insert(top);
|
||||
}
|
||||
u = v;
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ void wireStartToTops(NGHolder &g, const flat_set<NFAVertex> &tops,
|
||||
for (NFAVertex v : tops) {
|
||||
assert(!isLeafNode(v, g));
|
||||
|
||||
const NFAEdge &e = add_edge(g.start, v, g).first;
|
||||
const NFAEdge &e = add_edge(g.start, v, g);
|
||||
tempEdges.push_back(e);
|
||||
}
|
||||
}
|
||||
|
@@ -871,7 +871,7 @@ u32 removeTrailingLiteralStates(NGHolder &g, const ue2_literal &lit,
|
||||
clearReports(g);
|
||||
|
||||
for (auto v : pred) {
|
||||
NFAEdge e = add_edge(v, g.accept, g).first;
|
||||
NFAEdge e = add_edge(v, g.accept, g);
|
||||
g[v].reports.insert(0);
|
||||
if (is_triggered(g) && v == g.start) {
|
||||
g[e].tops.insert(DEFAULT_TOP);
|
||||
@@ -904,7 +904,7 @@ void restoreTrailingLiteralStates(NGHolder &g, const ue2_literal &lit,
|
||||
}
|
||||
|
||||
for (auto v : preds) {
|
||||
NFAEdge e = add_edge(v, prev, g).first;
|
||||
NFAEdge e = add_edge(v, prev, g);
|
||||
if (v == g.start && is_triggered(g)) {
|
||||
g[e].tops.insert(DEFAULT_TOP);
|
||||
}
|
||||
@@ -2408,14 +2408,14 @@ void explodeLiteral(RoseInGraph &g, RoseInVertex v,
|
||||
g[v_new].s = lit;
|
||||
|
||||
for (const auto &e : in_edges_range(v, g)) {
|
||||
RoseInEdge e2 = add_edge(source(e, g), v_new, g[e], g).first;
|
||||
RoseInEdge e2 = add_edge(source(e, g), v_new, g[e], g);
|
||||
// FIXME: are we safe to share graphs here? For now, make our very
|
||||
// own copy.
|
||||
g[e2].graph = makeGraphCopy(g[e].graph.get());
|
||||
}
|
||||
|
||||
for (const auto &e : out_edges_range(v, g)) {
|
||||
RoseInEdge e2 = add_edge(v_new, target(e, g), g[e], g).first;
|
||||
RoseInEdge e2 = add_edge(v_new, target(e, g), g[e], g);
|
||||
// FIXME: are we safe to share graphs here? For now, make our very
|
||||
// own copy.
|
||||
g[e2].graph = makeGraphCopy(g[e].graph.get());
|
||||
|
@@ -151,7 +151,7 @@ void splitRHS(const NGHolder &base, const vector<NFAVertex> &pivots,
|
||||
|
||||
for (auto pivot : pivots) {
|
||||
assert(contains(*rhs_map, pivot));
|
||||
NFAEdge e = add_edge(rhs->start, (*rhs_map)[pivot], *rhs).first;
|
||||
NFAEdge e = add_edge(rhs->start, (*rhs_map)[pivot], *rhs);
|
||||
(*rhs)[e].tops.insert(DEFAULT_TOP);
|
||||
}
|
||||
|
||||
|
@@ -197,12 +197,9 @@ u32 commonPrefixLength(const NGHolder &ga, const ranking_info &a_ranking,
|
||||
|
||||
a_count++;
|
||||
|
||||
NFAEdge b_edge;
|
||||
bool has_b_edge;
|
||||
tie(b_edge, has_b_edge) = edge(b_ranking.at(i),
|
||||
b_ranking.at(sid), gb);
|
||||
NFAEdge b_edge = edge(b_ranking.at(i), b_ranking.at(sid), gb);
|
||||
|
||||
if (!has_b_edge) {
|
||||
if (!b_edge) {
|
||||
max = i;
|
||||
DEBUG_PRINTF("lowering max to %u due to edge %zu->%u\n",
|
||||
max, i, sid);
|
||||
@@ -322,7 +319,7 @@ void mergeNfaComponent(NGHolder &dest, const NGHolder &vic, size_t common_len) {
|
||||
DEBUG_PRINTF("skipping common edge\n");
|
||||
assert(edge(u, v, dest).second);
|
||||
// Should never merge edges with different top values.
|
||||
assert(vic[e].tops == dest[edge(u, v, dest).first].tops);
|
||||
assert(vic[e].tops == dest[edge(u, v, dest)].tops);
|
||||
continue;
|
||||
} else {
|
||||
assert(is_any_accept(v, dest));
|
||||
@@ -508,25 +505,22 @@ bool mergeableStarts(const NGHolder &h1, const NGHolder &h2) {
|
||||
/* TODO: relax top checks if reports match */
|
||||
|
||||
// If both graphs have edge (start, accept), the tops must match.
|
||||
auto e1_accept = edge(h1.start, h1.accept, h1);
|
||||
auto e2_accept = edge(h2.start, h2.accept, h2);
|
||||
if (e1_accept.second && e2_accept.second &&
|
||||
h1[e1_accept.first].tops != h2[e2_accept.first].tops) {
|
||||
NFAEdge e1_accept = edge(h1.start, h1.accept, h1);
|
||||
NFAEdge e2_accept = edge(h2.start, h2.accept, h2);
|
||||
if (e1_accept && e2_accept && h1[e1_accept].tops != h2[e2_accept].tops) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If both graphs have edge (start, acceptEod), the tops must match.
|
||||
auto e1_eod = edge(h1.start, h1.acceptEod, h1);
|
||||
auto e2_eod = edge(h2.start, h2.acceptEod, h2);
|
||||
if (e1_eod.second && e2_eod.second &&
|
||||
h1[e1_eod.first].tops != h2[e2_eod.first].tops) {
|
||||
NFAEdge e1_eod = edge(h1.start, h1.acceptEod, h1);
|
||||
NFAEdge e2_eod = edge(h2.start, h2.acceptEod, h2);
|
||||
if (e1_eod && e2_eod && h1[e1_eod].tops != h2[e2_eod].tops) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If one graph has an edge to accept and the other has an edge to
|
||||
// acceptEod, the reports must match for the merge to be safe.
|
||||
if ((e1_accept.second && e2_eod.second) ||
|
||||
(e2_accept.second && e1_eod.second)) {
|
||||
if ((e1_accept && e2_eod) || (e2_accept && e1_eod)) {
|
||||
if (h1[h1.start].reports != h2[h2.start].reports) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -146,7 +146,7 @@ void clone_out_edges(NGHolder &g, NFAVertex source, NFAVertex dest) {
|
||||
if (edge(dest, t, g).second) {
|
||||
continue;
|
||||
}
|
||||
NFAEdge clone = add_edge(dest, t, g).first;
|
||||
NFAEdge clone = add_edge(dest, t, g);
|
||||
u32 idx = g[clone].index;
|
||||
g[clone] = g[e];
|
||||
g[clone].index = idx;
|
||||
@@ -157,7 +157,7 @@ void clone_in_edges(NGHolder &g, NFAVertex s, NFAVertex dest) {
|
||||
for (const auto &e : in_edges_range(s, g)) {
|
||||
NFAVertex ss = source(e, g);
|
||||
assert(!edge(ss, dest, g).second);
|
||||
NFAEdge clone = add_edge(ss, dest, g).first;
|
||||
NFAEdge clone = add_edge(ss, dest, g);
|
||||
u32 idx = g[clone].index;
|
||||
g[clone] = g[e];
|
||||
g[clone].index = idx;
|
||||
@@ -324,11 +324,9 @@ bool can_only_match_at_eod(const NGHolder &g) {
|
||||
}
|
||||
|
||||
bool matches_everywhere(const NGHolder &h) {
|
||||
NFAEdge e;
|
||||
bool exists;
|
||||
tie(e, exists) = edge(h.startDs, h.accept, h);
|
||||
NFAEdge e = edge(h.startDs, h.accept, h);
|
||||
|
||||
return exists && !h[e].assert_flags;
|
||||
return e && !h[e].assert_flags;
|
||||
}
|
||||
|
||||
bool is_virtual_start(NFAVertex v, const NGHolder &g) {
|
||||
@@ -623,10 +621,7 @@ void cloneHolder(NGHolder &out, const NGHolder &in) {
|
||||
|
||||
NFAVertex s = out_mapping[si];
|
||||
NFAVertex t = out_mapping[ti];
|
||||
UNUSED bool added;
|
||||
NFAEdge e2;
|
||||
tie(e2, added) = add_edge(s, t, out);
|
||||
assert(added);
|
||||
NFAEdge e2 = add_edge(s, t, out);
|
||||
out[e2] = in[e];
|
||||
}
|
||||
|
||||
|
@@ -1153,7 +1153,7 @@ void splitEdgesByCut(NGHolder &h, RoseInGraph &vg,
|
||||
* makes a more svelte graphy */
|
||||
clear_in_edges(temp_map[pivot], *new_lhs);
|
||||
NFAEdge pivot_edge = add_edge(temp_map[prev_v], temp_map[pivot],
|
||||
*new_lhs).first;
|
||||
*new_lhs);
|
||||
if (is_triggered(h) && prev_v == h.start) {
|
||||
(*new_lhs)[pivot_edge].tops.insert(DEFAULT_TOP);
|
||||
}
|
||||
@@ -2125,7 +2125,7 @@ void splitEdgesForSuffix(const NGHolder &base_graph, RoseInGraph &vg,
|
||||
add_edge(lhs->accept, lhs->acceptEod, *lhs);
|
||||
clearReports(*lhs);
|
||||
for (NFAVertex v : splitters) {
|
||||
NFAEdge e = add_edge(v_map[v], lhs->accept, *lhs).first;
|
||||
NFAEdge e = add_edge(v_map[v], lhs->accept, *lhs);
|
||||
if (v == base_graph.start) {
|
||||
(*lhs)[e].tops.insert(DEFAULT_TOP);
|
||||
}
|
||||
|
Reference in New Issue
Block a user