From 8d178d52ef3bd82663882d2002bee185110c3f18 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Thu, 29 Jun 2017 11:33:03 +1000 Subject: [PATCH] ng_util: use small_color_map --- src/nfagraph/ng_util.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/nfagraph/ng_util.cpp b/src/nfagraph/ng_util.cpp index c0ad6199..197ac66d 100644 --- a/src/nfagraph/ng_util.cpp +++ b/src/nfagraph/ng_util.cpp @@ -39,6 +39,7 @@ #include "nfa/limex_limits.h" // for NFA_MAX_TOP_MASKS. #include "parser/position.h" #include "util/graph_range.h" +#include "util/graph_small_color_map.h" #include "util/make_unique.h" #include "util/order_check.h" #include "util/ue2string.h" @@ -52,7 +53,6 @@ #include using namespace std; -using boost::default_color_type; using boost::make_filtered_graph; using boost::make_assoc_property_map; @@ -226,15 +226,12 @@ bool isAcyclic(const NGHolder &g) { /** True if the graph has a cycle reachable from the given source vertex. */ bool hasReachableCycle(const NGHolder &g, NFAVertex src) { assert(hasCorrectlyNumberedVertices(g)); - vector colors(num_vertices(g)); try { // Use depth_first_visit, rather than depth_first_search, so that we // only search from src. - auto index_map = get(vertex_index, g); boost::depth_first_visit(g, src, DetectCycles(g), - make_iterator_property_map(colors.begin(), - index_map)); + make_small_color_map(g)); } catch (const CycleFound &) { return true; } @@ -353,24 +350,19 @@ vector getTopoOrdering(const NGHolder &g) { // Use the same colour map for both DFS and topological_sort below: avoids // having to reallocate it, etc. - const size_t num_verts = num_vertices(g); - vector colour(num_verts); + auto colors = make_small_color_map(g); using EdgeSet = ue2::unordered_set; EdgeSet backEdges; BackEdges be(backEdges); - auto index_map = get(vertex_index, g); - depth_first_search(g, visitor(be).root_vertex(g.start) - .color_map(make_iterator_property_map( - colour.begin(), index_map))); + depth_first_search(g, visitor(be).root_vertex(g.start).color_map(colors)); auto acyclic_g = make_filtered_graph(g, make_bad_edge_filter(&backEdges)); vector ordering; - ordering.reserve(num_verts); - topological_sort(acyclic_g, back_inserter(ordering), - color_map(make_iterator_property_map(colour.begin(), index_map))); + ordering.reserve(num_vertices(g)); + topological_sort(acyclic_g, back_inserter(ordering), color_map(colors)); reorderSpecials(g, ordering); @@ -379,7 +371,7 @@ vector getTopoOrdering(const NGHolder &g) { static void mustBeSetBefore_int(NFAVertex u, const NGHolder &g, - vector &vertexColor) { + decltype(make_small_color_map(NGHolder())) &colors) { set s; insert(&s, adjacent_vertices(u, g)); @@ -396,10 +388,8 @@ void mustBeSetBefore_int(NFAVertex u, const NGHolder &g, auto prefix = make_filtered_graph(g, make_bad_edge_filter(&dead)); - depth_first_visit( - prefix, g.start, make_dfs_visitor(boost::null_visitor()), - make_iterator_property_map(vertexColor.begin(), - get(vertex_index, g))); + depth_first_visit(prefix, g.start, make_dfs_visitor(boost::null_visitor()), + colors); } bool mustBeSetBefore(NFAVertex u, NFAVertex v, const NGHolder &g, @@ -412,14 +402,14 @@ bool mustBeSetBefore(NFAVertex u, NFAVertex v, const NGHolder &g, return cache.cache[key]; } - vector vertexColor(num_vertices(g)); - mustBeSetBefore_int(u, g, vertexColor); + auto colors = make_small_color_map(g); + mustBeSetBefore_int(u, g, colors); for (auto vi : vertices_range(g)) { auto key2 = make_pair(g[u].index, g[vi].index); DEBUG_PRINTF("adding %zu %zu\n", key2.first, key2.second); assert(!contains(cache.cache, key2)); - bool value = vertexColor[g[vi].index] == boost::white_color; + bool value = get(colors, vi) == small_color::white; cache.cache[key2] = value; assert(contains(cache.cache, key2)); }