From 7ec757c7cef6f2f7f65ac6da210fb36e37cdfb4a Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Thu, 1 Jun 2017 14:40:04 +1000 Subject: [PATCH] ng_cyclic_redundancy: persist colour map --- src/nfagraph/ng_cyclic_redundancy.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/nfagraph/ng_cyclic_redundancy.cpp b/src/nfagraph/ng_cyclic_redundancy.cpp index 9ae4458c..e4138a4f 100644 --- a/src/nfagraph/ng_cyclic_redundancy.cpp +++ b/src/nfagraph/ng_cyclic_redundancy.cpp @@ -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 #include #include @@ -126,14 +127,16 @@ class SearchVisitor : public boost::default_dfs_visitor { template static bool searchForward(const Graph &g, const CharReach &reach, + vector &colours, const flat_set &s, typename Graph::vertex_descriptor w) { - map 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(s)); - } catch (SearchFailed&) { + depth_first_visit(g, w, SearchVisitor(reach), colour_map, + VertexInSet(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 colours(num_vertices(g)); + // precalc successors of v. flat_set 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) {