From 8b7b06d2a407d21cd777cfcdc123f625c93e5599 Mon Sep 17 00:00:00 2001 From: Alex Coyte Date: Fri, 2 Dec 2016 16:02:09 +1100 Subject: [PATCH] calcDepthFromSource: only take one copy of the graph --- src/nfagraph/ng_depth.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/nfagraph/ng_depth.cpp b/src/nfagraph/ng_depth.cpp index 5111b752..63e0e46b 100644 --- a/src/nfagraph/ng_depth.cpp +++ b/src/nfagraph/ng_depth.cpp @@ -162,13 +162,13 @@ void findLoopReachable(const GraphT &g, template static -void calcDepthFromSource(const NGHolder &graph, const GraphT &g, +void calcDepthFromSource(const GraphT &g, typename GraphT::vertex_descriptor srcVertex, - const vector &deadNodes, - vector &dMin, vector &dMax) { + const vector &deadNodes, vector &dMin, + vector &dMax) { typedef typename GraphT::edge_descriptor EdgeT; - const size_t numVerts = num_vertices(graph); + const size_t numVerts = num_vertices(g); NodeFilter nf(&deadNodes, &g); StartFilter sf(&g); @@ -252,14 +252,14 @@ DepthMinMax getDepths(u32 idx, const vector &dMin, template static -void calcAndStoreDepth(const NGHolder &h, const Graph &g, +void calcAndStoreDepth(const Graph &g, const typename Graph::vertex_descriptor src, const vector &deadNodes, vector &dMin /* util */, vector &dMax /* util */, vector &depths, DepthMinMax Output::*store) { - calcDepthFromSource(h, g, src, deadNodes, dMin, dMax); + calcDepthFromSource(g, src, deadNodes, dMin, dMax); for (auto v : vertices_range(g)) { u32 idx = g[v].index; @@ -286,10 +286,10 @@ void calcDepths(const NGHolder &g, std::vector &depths) { findLoopReachable(g, g.start, deadNodes); DEBUG_PRINTF("doing start\n"); - calcAndStoreDepth(g, g, g.start, deadNodes, dMin, dMax, depths, + calcAndStoreDepth(g, g.start, deadNodes, dMin, dMax, depths, &NFAVertexDepth::fromStart); DEBUG_PRINTF("doing startds\n"); - calcAndStoreDepth(g, g, g.startDs, deadNodes, dMin, dMax, depths, + calcAndStoreDepth(g, g.startDs, deadNodes, dMin, dMax, depths, &NFAVertexDepth::fromStartDotStar); } @@ -306,6 +306,8 @@ void calcDepths(const NGHolder &g, std::vector &depths) { typedef reverse_graph RevNFAGraph; const RevNFAGraph rg(g); + assert(num_vertices(g) == num_vertices(rg)); + /* * create a filtered graph for max depth calculations: all nodes/edges * reachable from a loop need to be removed @@ -315,12 +317,12 @@ void calcDepths(const NGHolder &g, std::vector &depths) { DEBUG_PRINTF("doing accept\n"); calcAndStoreDepth( - g, rg, g.accept, deadNodes, dMin, dMax, depths, + rg, g.accept, deadNodes, dMin, dMax, depths, &NFAVertexRevDepth::toAccept); DEBUG_PRINTF("doing accepteod\n"); deadNodes[NODE_ACCEPT] = true; // Hide accept->acceptEod edge. calcAndStoreDepth( - g, rg, g.acceptEod, deadNodes, dMin, dMax, depths, + rg, g.acceptEod, deadNodes, dMin, dMax, depths, &NFAVertexRevDepth::toAcceptEod); } @@ -342,11 +344,11 @@ void calcDepths(const NGHolder &g, vector &depths) { DEBUG_PRINTF("doing start\n"); calcAndStoreDepth( - g, g, g.start, deadNodes, dMin, dMax, depths, + g, g.start, deadNodes, dMin, dMax, depths, &NFAVertexBidiDepth::fromStart); DEBUG_PRINTF("doing startds\n"); calcAndStoreDepth( - g, g, g.startDs, deadNodes, dMin, dMax, depths, + g, g.startDs, deadNodes, dMin, dMax, depths, &NFAVertexBidiDepth::fromStartDotStar); /* Now go backwards */ @@ -357,12 +359,12 @@ void calcDepths(const NGHolder &g, vector &depths) { DEBUG_PRINTF("doing accept\n"); calcAndStoreDepth( - g, rg, g.accept, deadNodes, dMin, dMax, depths, + rg, g.accept, deadNodes, dMin, dMax, depths, &NFAVertexBidiDepth::toAccept); DEBUG_PRINTF("doing accepteod\n"); deadNodes[NODE_ACCEPT] = true; // Hide accept->acceptEod edge. calcAndStoreDepth( - g, rg, g.acceptEod, deadNodes, dMin, dMax, depths, + rg, g.acceptEod, deadNodes, dMin, dMax, depths, &NFAVertexBidiDepth::toAcceptEod); } @@ -375,7 +377,7 @@ void calcDepthsFrom(const NGHolder &g, const NFAVertex src, findLoopReachable(g, g.start, deadNodes); vector dMin, dMax; - calcDepthFromSource(g, g, src, deadNodes, dMin, dMax); + calcDepthFromSource(g, src, deadNodes, dMin, dMax); depths.clear(); depths.resize(numVertices);