From 0d402ae6f549af650fad17a852661ba14546d107 Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Mon, 23 Apr 2001 05:41:03 +0000 Subject: [PATCH] removed reference vertex_index in case when color_map param is provided [SVN r9899] --- include/boost/graph/depth_first_search.hpp | 112 +++++++++++---------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/include/boost/graph/depth_first_search.hpp b/include/boost/graph/depth_first_search.hpp index 3a412754..86ffddeb 100644 --- a/include/boost/graph/depth_first_search.hpp +++ b/include/boost/graph/depth_first_search.hpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace boost { @@ -61,7 +62,7 @@ namespace boost { namespace detail { template - void internal_depth_first_visit + void depth_first_visit_impl (const IncidenceGraph& g, typename graph_traits::vertex_descriptor u, DFSVisitor& vis, // pass-by-reference here, important! @@ -77,60 +78,72 @@ namespace boost { vis.discover_vertex(u, g); typename graph_traits::out_edge_iterator ei, ei_end; for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { - vis.examine_edge(*ei, g); - if (get(color, target(*ei, g)) == Color::white()) { - vis.tree_edge(*ei, g); - internal_depth_first_visit(g, target(*ei, g), vis, color); - } else if (get(color, target(*ei, g)) == Color::gray()) - vis.back_edge(*ei, g); - else - vis.forward_or_cross_edge(*ei, g); + vis.examine_edge(*ei, g); + if (get(color, target(*ei, g)) == Color::white()) { + vis.tree_edge(*ei, g); + depth_first_visit_impl(g, target(*ei, g), vis, color); + } else if (get(color, target(*ei, g)) == Color::gray()) + vis.back_edge(*ei, g); + else + vis.forward_or_cross_edge(*ei, g); } put(color, u, Color::black()); vis.finish_vertex(u, g); } - } - -#if 0 - // Deprecated - - // Variant (1) - template - inline void - depth_first_search(Graph& g, DFSVisitor v) - { - typedef typename graph_traits::vertex_descriptor Vertex; - depth_first_search(g, v, get(vertex_color, g)); - } -#endif - - // Variant (2) - template - void - depth_first_search(const VertexListGraph& g, DFSVisitor vis, ColorMap color) - { - function_requires >(); - typedef typename property_traits::value_type ColorValue; - typedef color_traits Color; - - typename graph_traits::vertex_iterator ui, ui_end; - for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { - put(color, *ui, Color::white()); - vis.initialize_vertex(*ui, g); - } - for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) - if (get(color, *ui) == Color::white()) { - vis.start_vertex(*ui, g); - detail::internal_depth_first_visit(g, *ui, vis, color); + template + void + dfs_impl(const VertexListGraph& g, DFSVisitor vis, ColorMap color) + { + function_requires >(); + typedef typename property_traits::value_type ColorValue; + typedef color_traits Color; + + typename graph_traits::vertex_iterator ui, ui_end; + for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { + put(color, *ui, Color::white()); + vis.initialize_vertex(*ui, g); } - } + for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) + if (get(color, *ui) == Color::white()) { + vis.start_vertex(*ui, g); + detail::depth_first_visit_impl(g, *ui, vis, color); + } + } + + template + void + dfs_dispatch(const VertexListGraph& g, DFSVisitor vis, + const bgl_named_params& params, + ColorMap color) + { + dfs_impl(g, vis, color); + } + + template + void + dfs_dispatch(const VertexListGraph& g, DFSVisitor vis, + const bgl_named_params& params, + detail::error_property_not_found) + { + std::vector color_vec(num_vertices(g)); + dfs_impl(g, vis, + make_iterator_property_map + (color_vec.begin(), + choose_const_pmap(get_param(params, vertex_index), + g, vertex_index)) ); + } + + } // namespace detail + // Named Parameter Variant template void depth_first_search(const VertexListGraph& g, - const bgl_named_params& params) + const bgl_named_params& params) { // ColorMap default typename graph_traits::vertices_size_type @@ -138,15 +151,12 @@ namespace boost { num_vertices(g) : 0; std::vector color_map(n); - depth_first_search + detail::dfs_dispatch (g, choose_param(get_param(params, graph_visitor), make_dfs_visitor(null_visitor())), - choose_param - (get_param(params, vertex_color), - make_iterator_property_map - (color_map.begin(), - choose_const_pmap(get_param(params, vertex_index), g, vertex_index))) + params, + get_param(params, vertex_color) ); } @@ -157,7 +167,7 @@ namespace boost { typename graph_traits::vertex_descriptor u, DFSVisitor vis, ColorMap color) { - detail::internal_depth_first_visit(g, u, vis, color); + detail::depth_first_visit_impl(g, u, vis, color); }