mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-10-10 08:12:21 +03:00
Introduce custom adjacency-list based graph
This commit is contained in:
@@ -65,9 +65,8 @@ bool is_dot(NFAVertex v, const GraphT &g) {
|
||||
template<class U>
|
||||
static really_inline
|
||||
void succ(const NGHolder &g, NFAVertex v, U *s) {
|
||||
NGHolder::adjacency_iterator ai, ae;
|
||||
tie(ai, ae) = adjacent_vertices(v, g);
|
||||
s->insert(ai, ae);
|
||||
auto rv = adjacent_vertices(v, g);
|
||||
s->insert(rv.first, rv.second);
|
||||
}
|
||||
|
||||
template<class ContTemp = flat_set<NFAVertex>>
|
||||
@@ -81,9 +80,8 @@ ContTemp succs(NFAVertex u, const NGHolder &g) {
|
||||
template<class U>
|
||||
static really_inline
|
||||
void pred(const NGHolder &g, NFAVertex v, U *p) {
|
||||
NGHolder::inv_adjacency_iterator it, ite;
|
||||
tie(it, ite) = inv_adjacent_vertices(v, g);
|
||||
p->insert(it, ite);
|
||||
auto rv = inv_adjacent_vertices(v, g);
|
||||
p->insert(rv.first, rv.second);
|
||||
}
|
||||
|
||||
template<class ContTemp = flat_set<NFAVertex>>
|
||||
@@ -138,42 +136,11 @@ public:
|
||||
BackEdgeSet &backEdges;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic code to renumber all the vertices in a graph. Assumes that we're
|
||||
* using a vertex_index property of type u32, and that we always have
|
||||
* N_SPECIALS special vertices already present (which we don't want to
|
||||
* renumber).
|
||||
*/
|
||||
template<typename GraphT>
|
||||
static really_inline
|
||||
size_t renumberGraphVertices(GraphT &g) {
|
||||
size_t num = N_SPECIALS;
|
||||
for (const auto &v : vertices_range(g)) {
|
||||
if (!is_special(v, g)) {
|
||||
g[v].index = num++;
|
||||
assert(num > 0); // no wrapping
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/** Renumber all the edges in a graph. */
|
||||
template<typename GraphT>
|
||||
static really_inline
|
||||
size_t renumberGraphEdges(GraphT &g) {
|
||||
size_t num = 0;
|
||||
for (const auto &e : edges_range(g)) {
|
||||
g[e].index = num++;
|
||||
assert(num > 0); // no wrapping
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/** Returns true if the vertex is either of the real starts (NODE_START,
|
||||
* NODE_START_DOTSTAR). */
|
||||
template <typename GraphT>
|
||||
static really_inline
|
||||
bool is_any_start(const NFAVertex v, const GraphT &g) {
|
||||
bool is_any_start(typename GraphT::vertex_descriptor v, const GraphT &g) {
|
||||
u32 i = g[v].index;
|
||||
return i == NODE_START || i == NODE_START_DOTSTAR;
|
||||
}
|
||||
@@ -181,16 +148,14 @@ bool is_any_start(const NFAVertex v, const GraphT &g) {
|
||||
bool is_virtual_start(NFAVertex v, const NGHolder &g);
|
||||
|
||||
template <typename GraphT>
|
||||
static really_inline
|
||||
bool is_any_accept(const NFAVertex v, const GraphT &g) {
|
||||
bool is_any_accept(typename GraphT::vertex_descriptor v, const GraphT &g) {
|
||||
u32 i = g[v].index;
|
||||
return i == NODE_ACCEPT || i == NODE_ACCEPT_EOD;
|
||||
}
|
||||
|
||||
/** returns true iff v has an edge to accept or acceptEod */
|
||||
template <typename GraphT>
|
||||
static really_inline
|
||||
bool is_match_vertex(NFAVertex v, const GraphT &g) {
|
||||
bool is_match_vertex(typename GraphT::vertex_descriptor v, const GraphT &g) {
|
||||
return edge(v, g.accept, g).second || edge(v, g.acceptEod, g).second;
|
||||
}
|
||||
|
||||
@@ -202,25 +167,6 @@ bool is_match_vertex(NFAVertex v, const GraphT &g) {
|
||||
*/
|
||||
std::vector<NFAVertex> getTopoOrdering(const NGHolder &g);
|
||||
|
||||
/** Comparison functor used to sort by vertex_index. */
|
||||
template<typename Graph>
|
||||
struct VertexIndexOrdering {
|
||||
VertexIndexOrdering(const Graph &g_in) : g(&g_in) {}
|
||||
bool operator()(typename Graph::vertex_descriptor a,
|
||||
typename Graph::vertex_descriptor b) const {
|
||||
assert(a == b || (*g)[a].index != (*g)[b].index);
|
||||
return (*g)[a].index < (*g)[b].index;
|
||||
}
|
||||
private:
|
||||
const Graph *g;
|
||||
};
|
||||
|
||||
template<typename Graph>
|
||||
static
|
||||
VertexIndexOrdering<Graph> make_index_ordering(const Graph &g) {
|
||||
return VertexIndexOrdering<Graph>(g);
|
||||
}
|
||||
|
||||
bool onlyOneTop(const NGHolder &g);
|
||||
|
||||
/** Return the set of the tops on the given graph. */
|
||||
@@ -340,18 +286,6 @@ void reverseHolder(const NGHolder &g, NGHolder &out);
|
||||
*/
|
||||
bool allMatchStatesHaveReports(const NGHolder &g);
|
||||
|
||||
/**
|
||||
* Assertion: returns true if the vertices in this graph are contiguously (and
|
||||
* uniquely) numbered from zero.
|
||||
*/
|
||||
bool hasCorrectlyNumberedVertices(const NGHolder &g);
|
||||
|
||||
/**
|
||||
* Assertion: returns true if the edges in this graph are contiguously (and
|
||||
* uniquely) numbered from zero.
|
||||
*/
|
||||
bool hasCorrectlyNumberedEdges(const NGHolder &g);
|
||||
|
||||
/**
|
||||
* Assertion: returns true if the graph is triggered and all edges out of start
|
||||
* have tops OR if the graph is not-triggered and all edges out of start have no
|
||||
|
Reference in New Issue
Block a user