diff --git a/src/nfagraph/ng_depth.cpp b/src/nfagraph/ng_depth.cpp index 6c45fa2f..67a6b27b 100644 --- a/src/nfagraph/ng_depth.cpp +++ b/src/nfagraph/ng_depth.cpp @@ -124,34 +124,35 @@ private: } // namespace -template +template static -void findLoopReachable(const GraphT &g, - const typename GraphT::vertex_descriptor srcVertex, - vector &deadNodes) { - typedef typename GraphT::edge_descriptor EdgeT; - typedef typename GraphT::vertex_descriptor VertexT; - typedef set EdgeSet; +vector findLoopReachable(const Graph &g, + const typename Graph::vertex_descriptor src) { + vector deadNodes(num_vertices(g)); + + using Edge = typename Graph::edge_descriptor; + using Vertex = typename Graph::vertex_descriptor; + using EdgeSet = set; EdgeSet deadEdges; BackEdges be(deadEdges); - depth_first_search(g, visitor(be).root_vertex(srcVertex)); + depth_first_search(g, visitor(be).root_vertex(src)); auto af = make_bad_edge_filter(&deadEdges); auto acyclic_g = make_filtered_graph(g, af); - vector topoOrder; /* actually reverse topological order */ + vector topoOrder; /* actually reverse topological order */ topoOrder.reserve(deadNodes.size()); topological_sort(acyclic_g, back_inserter(topoOrder)); for (const auto &e : deadEdges) { - u32 srcIdx = g[source(e, g)].index; + size_t srcIdx = g[source(e, g)].index; if (srcIdx != NODE_START_DOTSTAR) { deadNodes[srcIdx] = true; } } - for (VertexT v : reverse(topoOrder)) { + for (auto v : reverse(topoOrder)) { for (const auto &e : in_edges_range(v, g)) { if (deadNodes[g[source(e, g)].index]) { deadNodes[g[v].index] = true; @@ -159,6 +160,8 @@ void findLoopReachable(const GraphT &g, } } } + + return deadNodes; } template @@ -282,8 +285,7 @@ vector calcDepths(const NGHolder &g) { * create a filtered graph for max depth calculations: all nodes/edges * reachable from a loop need to be removed */ - vector deadNodes(numVertices); - findLoopReachable(g, g.start, deadNodes); + auto deadNodes = findLoopReachable(g, g.start); DEBUG_PRINTF("doing start\n"); calcAndStoreDepth(g, g.start, deadNodes, dMin, dMax, depths, @@ -313,8 +315,7 @@ vector calcRevDepths(const NGHolder &g) { * create a filtered graph for max depth calculations: all nodes/edges * reachable from a loop need to be removed */ - vector deadNodes(numVertices); - findLoopReachable(rg, g.acceptEod, deadNodes); + auto deadNodes = findLoopReachable(rg, g.acceptEod); DEBUG_PRINTF("doing accept\n"); calcAndStoreDepth( @@ -341,8 +342,7 @@ vector calcBidiDepths(const NGHolder &g) { * create a filtered graph for max depth calculations: all nodes/edges * reachable from a loop need to be removed */ - vector deadNodes(numVertices); - findLoopReachable(g, g.start, deadNodes); + auto deadNodes = findLoopReachable(g, g.start); DEBUG_PRINTF("doing start\n"); calcAndStoreDepth( @@ -356,8 +356,7 @@ vector calcBidiDepths(const NGHolder &g) { /* Now go backwards */ typedef reverse_graph RevNFAGraph; const RevNFAGraph rg(g); - deadNodes.assign(numVertices, false); - findLoopReachable(rg, g.acceptEod, deadNodes); + deadNodes = findLoopReachable(rg, g.acceptEod); DEBUG_PRINTF("doing accept\n"); calcAndStoreDepth( @@ -376,8 +375,7 @@ vector calcDepthsFrom(const NGHolder &g, const NFAVertex src) { assert(hasCorrectlyNumberedVertices(g)); const size_t numVertices = num_vertices(g); - vector deadNodes(numVertices); - findLoopReachable(g, g.start, deadNodes); + auto deadNodes = findLoopReachable(g, g.start); vector dMin, dMax; calcDepthFromSource(g, src, deadNodes, dMin, dMax);