]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ng_cyclic_redundancy: persist colour map
authorJustin Viiret <justin.viiret@intel.com>
Thu, 1 Jun 2017 04:40:04 +0000 (14:40 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:10:11 +0000 (11:10 +1000)
src/nfagraph/ng_cyclic_redundancy.cpp

index 9ae4458c6b1ec7b0ae65d2f74ce88a6a4be82c03..e4138a4fbf4bc122559708a92b60a9ec515585c5 100644 (file)
@@ -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
  * modification, are permitted provided that the following conditions are met:
@@ -65,6 +65,7 @@
 #include "util/graph_range.h"
 #include "util/ue2_containers.h"
 
+#include <algorithm>
 #include <boost/graph/depth_first_search.hpp>
 #include <boost/graph/reverse_graph.hpp>
 
@@ -126,14 +127,16 @@ class SearchVisitor : public boost::default_dfs_visitor {
 template<class Graph>
 static
 bool searchForward(const Graph &g, const CharReach &reach,
+                   vector<boost::default_color_type> &colours,
                    const flat_set<typename Graph::vertex_descriptor> &s,
                    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 {
-        depth_first_visit(g, w, SearchVisitor(reach),
-                     make_assoc_property_map(colours),
-                     VertexInSet<typename Graph::vertex_descriptor, Graph>(s));
-    } catch (SearchFailed&) {
+        depth_first_visit(g, w, SearchVisitor(reach), colour_map,
+            VertexInSet<typename Graph::vertex_descriptor, Graph>(s));
+    } catch (SearchFailed &) {
         return false;
     }
 
@@ -162,6 +165,9 @@ bool removeCyclicPathRedundancy(Graph &g, typename Graph::vertex_descriptor v,
 
     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.
     flat_set<vertex_descriptor> succ_v;
     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);
 
-            if (!searchForward(g, reach, s, w)) {
+            if (!searchForward(g, reach, colours, s, w)) {
                 continue;
             }
 
@@ -234,6 +240,8 @@ bool cyclicPathRedundancyPass(Graph &g, NGHolder &raw) {
 }
 
 bool removeCyclicPathRedundancy(NGHolder &g) {
+    assert(hasCorrectlyNumberedVertices(g));
+
     // Forward pass.
     bool f_changed = cyclicPathRedundancyPass(g, g);
     if (f_changed) {