mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
calcDepthFromSource: only take one copy of the graph
This commit is contained in:
parent
582f71c5bb
commit
8b7b06d2a4
@ -162,13 +162,13 @@ void findLoopReachable(const GraphT &g,
|
|||||||
|
|
||||||
template <class GraphT>
|
template <class GraphT>
|
||||||
static
|
static
|
||||||
void calcDepthFromSource(const NGHolder &graph, const GraphT &g,
|
void calcDepthFromSource(const GraphT &g,
|
||||||
typename GraphT::vertex_descriptor srcVertex,
|
typename GraphT::vertex_descriptor srcVertex,
|
||||||
const vector<bool> &deadNodes,
|
const vector<bool> &deadNodes, vector<int> &dMin,
|
||||||
vector<int> &dMin, vector<int> &dMax) {
|
vector<int> &dMax) {
|
||||||
typedef typename GraphT::edge_descriptor EdgeT;
|
typedef typename GraphT::edge_descriptor EdgeT;
|
||||||
|
|
||||||
const size_t numVerts = num_vertices(graph);
|
const size_t numVerts = num_vertices(g);
|
||||||
|
|
||||||
NodeFilter<GraphT> nf(&deadNodes, &g);
|
NodeFilter<GraphT> nf(&deadNodes, &g);
|
||||||
StartFilter<GraphT> sf(&g);
|
StartFilter<GraphT> sf(&g);
|
||||||
@ -252,14 +252,14 @@ DepthMinMax getDepths(u32 idx, const vector<int> &dMin,
|
|||||||
|
|
||||||
template<class Graph, class Output>
|
template<class Graph, class Output>
|
||||||
static
|
static
|
||||||
void calcAndStoreDepth(const NGHolder &h, const Graph &g,
|
void calcAndStoreDepth(const Graph &g,
|
||||||
const typename Graph::vertex_descriptor src,
|
const typename Graph::vertex_descriptor src,
|
||||||
const vector<bool> &deadNodes,
|
const vector<bool> &deadNodes,
|
||||||
vector<int> &dMin /* util */,
|
vector<int> &dMin /* util */,
|
||||||
vector<int> &dMax /* util */,
|
vector<int> &dMax /* util */,
|
||||||
vector<Output> &depths,
|
vector<Output> &depths,
|
||||||
DepthMinMax Output::*store) {
|
DepthMinMax Output::*store) {
|
||||||
calcDepthFromSource(h, g, src, deadNodes, dMin, dMax);
|
calcDepthFromSource(g, src, deadNodes, dMin, dMax);
|
||||||
|
|
||||||
for (auto v : vertices_range(g)) {
|
for (auto v : vertices_range(g)) {
|
||||||
u32 idx = g[v].index;
|
u32 idx = g[v].index;
|
||||||
@ -286,10 +286,10 @@ void calcDepths(const NGHolder &g, std::vector<NFAVertexDepth> &depths) {
|
|||||||
findLoopReachable(g, g.start, deadNodes);
|
findLoopReachable(g, g.start, deadNodes);
|
||||||
|
|
||||||
DEBUG_PRINTF("doing start\n");
|
DEBUG_PRINTF("doing start\n");
|
||||||
calcAndStoreDepth(g, g, g.start, deadNodes, dMin, dMax, depths,
|
calcAndStoreDepth(g, g.start, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexDepth::fromStart);
|
&NFAVertexDepth::fromStart);
|
||||||
DEBUG_PRINTF("doing startds\n");
|
DEBUG_PRINTF("doing startds\n");
|
||||||
calcAndStoreDepth(g, g, g.startDs, deadNodes, dMin, dMax, depths,
|
calcAndStoreDepth(g, g.startDs, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexDepth::fromStartDotStar);
|
&NFAVertexDepth::fromStartDotStar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,6 +306,8 @@ void calcDepths(const NGHolder &g, std::vector<NFAVertexRevDepth> &depths) {
|
|||||||
typedef reverse_graph<NGHolder, const NGHolder &> RevNFAGraph;
|
typedef reverse_graph<NGHolder, const NGHolder &> RevNFAGraph;
|
||||||
const RevNFAGraph rg(g);
|
const RevNFAGraph rg(g);
|
||||||
|
|
||||||
|
assert(num_vertices(g) == num_vertices(rg));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create a filtered graph for max depth calculations: all nodes/edges
|
* create a filtered graph for max depth calculations: all nodes/edges
|
||||||
* reachable from a loop need to be removed
|
* reachable from a loop need to be removed
|
||||||
@ -315,12 +317,12 @@ void calcDepths(const NGHolder &g, std::vector<NFAVertexRevDepth> &depths) {
|
|||||||
|
|
||||||
DEBUG_PRINTF("doing accept\n");
|
DEBUG_PRINTF("doing accept\n");
|
||||||
calcAndStoreDepth<RevNFAGraph, NFAVertexRevDepth>(
|
calcAndStoreDepth<RevNFAGraph, NFAVertexRevDepth>(
|
||||||
g, rg, g.accept, deadNodes, dMin, dMax, depths,
|
rg, g.accept, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexRevDepth::toAccept);
|
&NFAVertexRevDepth::toAccept);
|
||||||
DEBUG_PRINTF("doing accepteod\n");
|
DEBUG_PRINTF("doing accepteod\n");
|
||||||
deadNodes[NODE_ACCEPT] = true; // Hide accept->acceptEod edge.
|
deadNodes[NODE_ACCEPT] = true; // Hide accept->acceptEod edge.
|
||||||
calcAndStoreDepth<RevNFAGraph, NFAVertexRevDepth>(
|
calcAndStoreDepth<RevNFAGraph, NFAVertexRevDepth>(
|
||||||
g, rg, g.acceptEod, deadNodes, dMin, dMax, depths,
|
rg, g.acceptEod, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexRevDepth::toAcceptEod);
|
&NFAVertexRevDepth::toAcceptEod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,11 +344,11 @@ void calcDepths(const NGHolder &g, vector<NFAVertexBidiDepth> &depths) {
|
|||||||
|
|
||||||
DEBUG_PRINTF("doing start\n");
|
DEBUG_PRINTF("doing start\n");
|
||||||
calcAndStoreDepth<NGHolder, NFAVertexBidiDepth>(
|
calcAndStoreDepth<NGHolder, NFAVertexBidiDepth>(
|
||||||
g, g, g.start, deadNodes, dMin, dMax, depths,
|
g, g.start, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexBidiDepth::fromStart);
|
&NFAVertexBidiDepth::fromStart);
|
||||||
DEBUG_PRINTF("doing startds\n");
|
DEBUG_PRINTF("doing startds\n");
|
||||||
calcAndStoreDepth<NGHolder, NFAVertexBidiDepth>(
|
calcAndStoreDepth<NGHolder, NFAVertexBidiDepth>(
|
||||||
g, g, g.startDs, deadNodes, dMin, dMax, depths,
|
g, g.startDs, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexBidiDepth::fromStartDotStar);
|
&NFAVertexBidiDepth::fromStartDotStar);
|
||||||
|
|
||||||
/* Now go backwards */
|
/* Now go backwards */
|
||||||
@ -357,12 +359,12 @@ void calcDepths(const NGHolder &g, vector<NFAVertexBidiDepth> &depths) {
|
|||||||
|
|
||||||
DEBUG_PRINTF("doing accept\n");
|
DEBUG_PRINTF("doing accept\n");
|
||||||
calcAndStoreDepth<RevNFAGraph, NFAVertexBidiDepth>(
|
calcAndStoreDepth<RevNFAGraph, NFAVertexBidiDepth>(
|
||||||
g, rg, g.accept, deadNodes, dMin, dMax, depths,
|
rg, g.accept, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexBidiDepth::toAccept);
|
&NFAVertexBidiDepth::toAccept);
|
||||||
DEBUG_PRINTF("doing accepteod\n");
|
DEBUG_PRINTF("doing accepteod\n");
|
||||||
deadNodes[NODE_ACCEPT] = true; // Hide accept->acceptEod edge.
|
deadNodes[NODE_ACCEPT] = true; // Hide accept->acceptEod edge.
|
||||||
calcAndStoreDepth<RevNFAGraph, NFAVertexBidiDepth>(
|
calcAndStoreDepth<RevNFAGraph, NFAVertexBidiDepth>(
|
||||||
g, rg, g.acceptEod, deadNodes, dMin, dMax, depths,
|
rg, g.acceptEod, deadNodes, dMin, dMax, depths,
|
||||||
&NFAVertexBidiDepth::toAcceptEod);
|
&NFAVertexBidiDepth::toAcceptEod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +377,7 @@ void calcDepthsFrom(const NGHolder &g, const NFAVertex src,
|
|||||||
findLoopReachable(g, g.start, deadNodes);
|
findLoopReachable(g, g.start, deadNodes);
|
||||||
|
|
||||||
vector<int> dMin, dMax;
|
vector<int> dMin, dMax;
|
||||||
calcDepthFromSource(g, g, src, deadNodes, dMin, dMax);
|
calcDepthFromSource(g, src, deadNodes, dMin, dMax);
|
||||||
|
|
||||||
depths.clear();
|
depths.clear();
|
||||||
depths.resize(numVertices);
|
depths.resize(numVertices);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user