mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ng_cyclic_redundancy: persist colour map
This commit is contained in:
parent
fe2654b086
commit
7ec757c7ce
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2016, Intel Corporation
|
* Copyright (c) 2015-2017, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -65,6 +65,7 @@
|
|||||||
#include "util/graph_range.h"
|
#include "util/graph_range.h"
|
||||||
#include "util/ue2_containers.h"
|
#include "util/ue2_containers.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <boost/graph/depth_first_search.hpp>
|
#include <boost/graph/depth_first_search.hpp>
|
||||||
#include <boost/graph/reverse_graph.hpp>
|
#include <boost/graph/reverse_graph.hpp>
|
||||||
|
|
||||||
@ -126,12 +127,14 @@ class SearchVisitor : public boost::default_dfs_visitor {
|
|||||||
template<class Graph>
|
template<class Graph>
|
||||||
static
|
static
|
||||||
bool searchForward(const Graph &g, const CharReach &reach,
|
bool searchForward(const Graph &g, const CharReach &reach,
|
||||||
|
vector<boost::default_color_type> &colours,
|
||||||
const flat_set<typename Graph::vertex_descriptor> &s,
|
const flat_set<typename Graph::vertex_descriptor> &s,
|
||||||
typename Graph::vertex_descriptor w) {
|
typename Graph::vertex_descriptor w) {
|
||||||
map<NFAVertex, boost::default_color_type> colours;
|
fill(colours.begin(), colours.end(), boost::white_color);
|
||||||
|
auto colour_map =
|
||||||
|
make_iterator_property_map(colours.begin(), get(vertex_index, g));
|
||||||
try {
|
try {
|
||||||
depth_first_visit(g, w, SearchVisitor(reach),
|
depth_first_visit(g, w, SearchVisitor(reach), colour_map,
|
||||||
make_assoc_property_map(colours),
|
|
||||||
VertexInSet<typename Graph::vertex_descriptor, Graph>(s));
|
VertexInSet<typename Graph::vertex_descriptor, Graph>(s));
|
||||||
} catch (SearchFailed &) {
|
} catch (SearchFailed &) {
|
||||||
return false;
|
return false;
|
||||||
@ -162,6 +165,9 @@ bool removeCyclicPathRedundancy(Graph &g, typename Graph::vertex_descriptor v,
|
|||||||
|
|
||||||
typedef typename Graph::vertex_descriptor vertex_descriptor;
|
typedef typename Graph::vertex_descriptor vertex_descriptor;
|
||||||
|
|
||||||
|
// Colour map used for depth_first_visit().
|
||||||
|
vector<boost::default_color_type> colours(num_vertices(g));
|
||||||
|
|
||||||
// precalc successors of v.
|
// precalc successors of v.
|
||||||
flat_set<vertex_descriptor> succ_v;
|
flat_set<vertex_descriptor> succ_v;
|
||||||
insert(&succ_v, adjacent_vertices(v, g));
|
insert(&succ_v, adjacent_vertices(v, g));
|
||||||
@ -200,7 +206,7 @@ bool removeCyclicPathRedundancy(Graph &g, typename Graph::vertex_descriptor v,
|
|||||||
|
|
||||||
DEBUG_PRINTF(" - checking w %zu\n", g[w].index);
|
DEBUG_PRINTF(" - checking w %zu\n", g[w].index);
|
||||||
|
|
||||||
if (!searchForward(g, reach, s, w)) {
|
if (!searchForward(g, reach, colours, s, w)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +240,8 @@ bool cyclicPathRedundancyPass(Graph &g, NGHolder &raw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool removeCyclicPathRedundancy(NGHolder &g) {
|
bool removeCyclicPathRedundancy(NGHolder &g) {
|
||||||
|
assert(hasCorrectlyNumberedVertices(g));
|
||||||
|
|
||||||
// Forward pass.
|
// Forward pass.
|
||||||
bool f_changed = cyclicPathRedundancyPass(g, g);
|
bool f_changed = cyclicPathRedundancyPass(g, g);
|
||||||
if (f_changed) {
|
if (f_changed) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user