ng_prune: use small_color_map

This commit is contained in:
Justin Viiret 2017-06-29 11:25:13 +10:00 committed by Matthew Barr
parent 33141e64b6
commit f98ccedf27

View 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 * 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:
@ -38,6 +38,7 @@
#include "util/container.h" #include "util/container.h"
#include "util/graph.h" #include "util/graph.h"
#include "util/graph_range.h" #include "util/graph_range.h"
#include "util/graph_small_color_map.h"
#include "util/report_manager.h" #include "util/report_manager.h"
#include <deque> #include <deque>
@ -105,23 +106,18 @@ template<class nfag_t>
static static
bool pruneForwardUseless(NGHolder &h, const nfag_t &g, bool pruneForwardUseless(NGHolder &h, const nfag_t &g,
typename nfag_t::vertex_descriptor s, typename nfag_t::vertex_descriptor s,
vector<default_color_type> &vertexColor) { decltype(make_small_color_map(NGHolder())) &colors) {
// Begin with all vertices set to white, as DFV only marks visited // Begin with all vertices set to white, as DFV only marks visited
// vertices. // vertices.
fill(vertexColor.begin(), vertexColor.end(), boost::white_color); colors.fill(small_color::white);
auto index_map = get(&NFAGraphVertexProps::index, g); depth_first_visit(g, s, make_dfs_visitor(boost::null_visitor()), colors);
depth_first_visit(g, s, make_dfs_visitor(boost::null_visitor()),
make_iterator_property_map(vertexColor.begin(),
index_map));
vector<NFAVertex> dead; vector<NFAVertex> dead;
// All non-special vertices that are still white can be removed. // All non-special vertices that are still white can be removed.
for (auto v : vertices_range(g)) { for (auto v : vertices_range(g)) {
u32 idx = g[v].index; if (!is_special(v, g) && get(colors, v) == small_color::white) {
if (!is_special(v, g) && vertexColor[idx] == boost::white_color) {
DEBUG_PRINTF("vertex %zu is unreachable from %zu\n", DEBUG_PRINTF("vertex %zu is unreachable from %zu\n",
g[v].index, g[s].index); g[v].index, g[s].index);
dead.push_back(NFAVertex(v)); dead.push_back(NFAVertex(v));
@ -143,11 +139,11 @@ bool pruneForwardUseless(NGHolder &h, const nfag_t &g,
void pruneUseless(NGHolder &g, bool renumber) { void pruneUseless(NGHolder &g, bool renumber) {
DEBUG_PRINTF("pruning useless vertices\n"); DEBUG_PRINTF("pruning useless vertices\n");
assert(hasCorrectlyNumberedVertices(g)); assert(hasCorrectlyNumberedVertices(g));
vector<default_color_type> vertexColor(num_vertices(g)); auto colors = make_small_color_map(g);
bool work_done = pruneForwardUseless(g, g, g.start, vertexColor); bool work_done = pruneForwardUseless(g, g, g.start, colors);
work_done |= pruneForwardUseless(g, reverse_graph<NGHolder, NGHolder &>(g), work_done |= pruneForwardUseless(g, reverse_graph<NGHolder, NGHolder &>(g),
g.acceptEod, vertexColor); g.acceptEod, colors);
if (!work_done) { if (!work_done) {
return; return;