mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ng_depth: modernize findLoopReachable
This commit is contained in:
parent
dfe1b8a2af
commit
c17085ba35
@ -124,34 +124,35 @@ private:
|
||||
|
||||
} // namespace
|
||||
|
||||
template<class GraphT>
|
||||
template<class Graph>
|
||||
static
|
||||
void findLoopReachable(const GraphT &g,
|
||||
const typename GraphT::vertex_descriptor srcVertex,
|
||||
vector<bool> &deadNodes) {
|
||||
typedef typename GraphT::edge_descriptor EdgeT;
|
||||
typedef typename GraphT::vertex_descriptor VertexT;
|
||||
typedef set<EdgeT> EdgeSet;
|
||||
vector<bool> findLoopReachable(const Graph &g,
|
||||
const typename Graph::vertex_descriptor src) {
|
||||
vector<bool> deadNodes(num_vertices(g));
|
||||
|
||||
using Edge = typename Graph::edge_descriptor;
|
||||
using Vertex = typename Graph::vertex_descriptor;
|
||||
using EdgeSet = set<Edge>;
|
||||
|
||||
EdgeSet deadEdges;
|
||||
BackEdges<EdgeSet> 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<VertexT> topoOrder; /* actually reverse topological order */
|
||||
vector<Vertex> 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 <class GraphT>
|
||||
@ -282,8 +285,7 @@ vector<NFAVertexDepth> calcDepths(const NGHolder &g) {
|
||||
* create a filtered graph for max depth calculations: all nodes/edges
|
||||
* reachable from a loop need to be removed
|
||||
*/
|
||||
vector<bool> 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<NFAVertexRevDepth> calcRevDepths(const NGHolder &g) {
|
||||
* create a filtered graph for max depth calculations: all nodes/edges
|
||||
* reachable from a loop need to be removed
|
||||
*/
|
||||
vector<bool> deadNodes(numVertices);
|
||||
findLoopReachable(rg, g.acceptEod, deadNodes);
|
||||
auto deadNodes = findLoopReachable(rg, g.acceptEod);
|
||||
|
||||
DEBUG_PRINTF("doing accept\n");
|
||||
calcAndStoreDepth<RevNFAGraph, NFAVertexRevDepth>(
|
||||
@ -341,8 +342,7 @@ vector<NFAVertexBidiDepth> calcBidiDepths(const NGHolder &g) {
|
||||
* create a filtered graph for max depth calculations: all nodes/edges
|
||||
* reachable from a loop need to be removed
|
||||
*/
|
||||
vector<bool> deadNodes(numVertices);
|
||||
findLoopReachable(g, g.start, deadNodes);
|
||||
auto deadNodes = findLoopReachable(g, g.start);
|
||||
|
||||
DEBUG_PRINTF("doing start\n");
|
||||
calcAndStoreDepth<NGHolder, NFAVertexBidiDepth>(
|
||||
@ -356,8 +356,7 @@ vector<NFAVertexBidiDepth> calcBidiDepths(const NGHolder &g) {
|
||||
/* Now go backwards */
|
||||
typedef reverse_graph<NGHolder, const NGHolder &> 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<RevNFAGraph, NFAVertexBidiDepth>(
|
||||
@ -376,8 +375,7 @@ vector<DepthMinMax> calcDepthsFrom(const NGHolder &g, const NFAVertex src) {
|
||||
assert(hasCorrectlyNumberedVertices(g));
|
||||
const size_t numVertices = num_vertices(g);
|
||||
|
||||
vector<bool> deadNodes(numVertices);
|
||||
findLoopReachable(g, g.start, deadNodes);
|
||||
auto deadNodes = findLoopReachable(g, g.start);
|
||||
|
||||
vector<int> dMin, dMax;
|
||||
calcDepthFromSource(g, src, deadNodes, dMin, dMax);
|
||||
|
Loading…
x
Reference in New Issue
Block a user