diff --git "a/C:\\Users\\Jaeger\\AppData\\Local\\Temp\\TortoiseGit\\dep47F3.tmp\\depth_first_search-70a2630-left.hpp" "b/C:\\boost\\boost_github\\libs\\graph\\include\\boost\\graph\\depth_first_search.hpp" index b002d36..aeb91d7 100644 --- "a/C:\\Users\\Jaeger\\AppData\\Local\\Temp\\TortoiseGit\\dep47F3.tmp\\depth_first_search-70a2630-left.hpp" +++ "b/C:\\boost\\boost_github\\libs\\graph\\include\\boost\\graph\\depth_first_search.hpp" @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -79,6 +78,13 @@ namespace boost { do_call_finish_edge::value>::call_finish_edge(vis, e, g); } + template + struct dfs_context { + Vertex u; + Edge src_e; + Iter ei; + Iter ei_end; + }; // Define BOOST_RECURSIVE_DFS to use older, recursive version. // It is retained for a while in order to perform performance @@ -113,10 +119,8 @@ namespace boost { BOOST_CONCEPT_ASSERT(( ColorValueConcept )); typedef color_traits Color; typedef typename graph_traits::out_edge_iterator Iter; - typedef std::pair, std::pair > > VertexInfo; + typedef dfs_context VertexInfo; - boost::optional src_e; - Iter ei, ei_end; std::vector stack; // Possible optimization for vector @@ -124,47 +128,51 @@ namespace boost { put(color, u, Color::gray()); vis.discover_vertex(u, g); - boost::tie(ei, ei_end) = out_edges(u, g); - if (func(u, g)) { + + VertexInfo ctx; + ctx.u = u; + boost::tie(ctx.ei, ctx.ei_end) = out_edges(u, g); + if (func(ctx.u, g)) { // If this vertex terminates the search, we push empty range - stack.push_back(std::make_pair(u, std::make_pair(boost::optional(), std::make_pair(ei_end, ei_end)))); - } else { - stack.push_back(std::make_pair(u, std::make_pair(boost::optional(), std::make_pair(ei, ei_end)))); + ctx.ei = ctx.ei_end; } - while (!stack.empty()) { - VertexInfo& back = stack.back(); - u = back.first; - src_e = back.second.first; - boost::tie(ei, ei_end) = back.second.second; - stack.pop_back(); - while (ei != ei_end) { - Vertex v = target(*ei, g); - vis.examine_edge(*ei, g); + for ( ;; ) { + while ( ctx.ei != ctx.ei_end ) { + Edge e = *ctx.ei; + Vertex v = target(e, g); + vis.examine_edge(e, g); ColorValue v_color = get(color, v); if (v_color == Color::white()) { - vis.tree_edge(*ei, g); - src_e = *ei; - stack.push_back(std::make_pair(u, std::make_pair(src_e, std::make_pair(++ei, ei_end)))); - u = v; - put(color, u, Color::gray()); - vis.discover_vertex(u, g); - boost::tie(ei, ei_end) = out_edges(u, g); - if (func(u, g)) { - ei = ei_end; + vis.tree_edge(e, g); + ++ctx.ei; + stack.push_back(ctx); + ctx.src_e = e; + ctx.u = v; + put(color, ctx.u, Color::gray()); + vis.discover_vertex(ctx.u, g); + boost::tie(ctx.ei, ctx.ei_end) = out_edges(ctx.u, g); + if (func(ctx.u, g)) { + ctx.ei = ctx.ei_end; } } else { if (v_color == Color::gray()) { - vis.back_edge(*ei, g); + vis.back_edge(e, g); } else { - vis.forward_or_cross_edge(*ei, g); + vis.forward_or_cross_edge(e, g); } - call_finish_edge(vis, *ei, g); - ++ei; + call_finish_edge(vis, e, g); + ++ctx.ei; } } - put(color, u, Color::black()); - vis.finish_vertex(u, g); - if (src_e) call_finish_edge(vis, src_e.get(), g); + put(color, ctx.u, Color::black()); + vis.finish_vertex(ctx.u, g); + + if ( stack.empty() ) { + return; + } + call_finish_edge(vis, ctx.src_e, g); + ctx = stack.back(); + stack.pop_back(); } }