*** depth_first_search.hpp.orig Mon Aug 19 18:16:50 2002 --- depth_first_search.hpp Fri May 30 10:51:32 2003 *************** *** 27,33 **** #ifndef BOOST_GRAPH_RECURSIVE_DFS_HPP #define BOOST_GRAPH_RECURSIVE_DFS_HPP - #include #include #include #include --- 27,32 ---- *************** *** 35,40 **** --- 34,40 ---- #include #include #include + #include namespace boost { *************** *** 61,66 **** --- 61,133 ---- namespace detail { + #ifdef BOOST_NONRECURSIVE_DFS + + template + void depth_first_visit_impl + (const IncidenceGraph& g, + typename graph_traits::vertex_descriptor u, + DFSVisitor& vis, + ColorMap color) + { + function_requires >(); + function_requires >(); + typedef typename graph_traits::vertex_descriptor Vertex; + function_requires< ReadWritePropertyMapConcept >(); + typedef typename property_traits::value_type ColorValue; + function_requires< ColorValueConcept >(); + typedef color_traits Color; + typedef typename graph_traits::out_edge_iterator Iter; + typedef std::pair > VertexInfo; + + Iter ei, ei_end; + Vertex v; + ColorValue v_color; + std::vector stack; + + // Each item on the stack holds a vertex and its current out-edge + // iterators. The vertex is needed to restore the value of u when + // the stack is popped. + + // Possible optimization for vector + //stack.reserve(num_vertices(g)); + + stack.push_back(make_pair(u, out_edges(u, g))); + put(color, u, Color::gray()); + vis.discover_vertex(u, g); + + while (!stack.empty()) { + VertexInfo& back = stack.back(); + u = back.first; + tie(ei, ei_end) = back.second; + stack.pop_back(); + while (ei != ei_end) { + v = target(*ei, g); + vis.examine_edge(*ei, g); + v_color = get(color, v); + + if (v_color == Color::white()) { + vis.tree_edge(*ei, g); + stack.push_back(make_pair(u, make_pair(++ei, ei_end))); + u = v; + tie(ei, ei_end) = out_edges(u, g); + put(color, u, Color::gray()); + vis.discover_vertex(u, g); + } else if (v_color == Color::gray()) { + vis.back_edge(*ei, g); + ++ei; + } else { + vis.forward_or_cross_edge(*ei, g); + ++ei; + } + } + put(color, u, Color::black()); + vis.finish_vertex(u, g); + } + } + + #else // BOOST_NONRECURSIVE_DFS not defined + template void depth_first_visit_impl (const IncidenceGraph& g, *************** *** 88,93 **** --- 155,163 ---- } put(color, u, Color::black()); vis.finish_vertex(u, g); } + + #endif + } // namespace detail template