2 #ifndef ANDRES_GRAPH_DFS_HXX
3 #define ANDRES_GRAPH_DFS_HXX
11 #include "subgraph.hxx"
16 template<
typename S = std::
size_t>
24 template<
typename GRAPH>
26 : visited_(graph.numberOfVertices())
31 { stack_ = std::stack<size_type>(); }
33 {
return stack_.empty(); }
35 { std::fill(visited_.begin(), visited_.end(), 0); }
37 {
const size_type v = stack_.top(); stack_.pop();
return v; }
39 {
return visited_[v]; }
41 {
return visited_[v]; }
44 std::vector<unsigned char> visited_;
45 std::stack<size_type> stack_;
48 template<
typename GRAPH,
typename CALLBACK>
52 const std::size_t start_vertex,
60 template<typename GRAPH, typename CALLBACK, typename = typename std::enable_if<!std::is_lvalue_reference<CALLBACK>::value>::type>
64 const std::size_t start_vertex,
72 template<
typename GRAPH,
typename CALLBACK>
76 const std::size_t start_vertex,
84 template<typename GRAPH, typename CALLBACK, typename = typename std::enable_if<!std::is_lvalue_reference<CALLBACK>::value>::type>
88 const std::size_t start_vertex,
96 template<
typename GRAPH,
typename SUBGRAPH,
typename CALLBACK>
100 const SUBGRAPH& subgraph_mask,
101 const std::size_t start_vertex,
109 template<typename GRAPH, typename SUBGRAPH, typename CALLBACK, typename = typename std::enable_if<!std::is_lvalue_reference<CALLBACK>::value>::type>
113 const SUBGRAPH& subgraph_mask,
114 const std::size_t start_vertex,
122 template<
typename GRAPH,
typename SUBGRAPH,
typename CALLBACK>
126 const SUBGRAPH& subgraph_mask,
127 const std::size_t start_vertex,
132 assert(start_vertex < g.numberOfVertices());
134 data.
add(start_vertex);
138 auto v = data.
next();
147 callback(v, proceed, addNeighbors);
157 auto e_it = g.edgesFromVertexBegin(v);
158 for(
auto it = g.verticesFromVertexBegin(v); it != g.verticesFromVertexEnd(v); ++it, ++e_it)
159 if (!data.
visited(*it) && subgraph_mask.vertex(*it) && subgraph_mask.edge(*e_it))
166 template<typename GRAPH, typename SUBGRAPH, typename CALLBACK, typename = typename std::enable_if<!std::is_lvalue_reference<CALLBACK>::value>::type>
170 const SUBGRAPH& subgraph_mask,
171 const std::size_t start_vertex,