26 #ifndef MLN_CANVAS_BROWSING_INTERNAL_GRAPH_FIRST_SEARCH_HH
27 # define MLN_CANVAS_BROWSING_INTERNAL_GRAPH_FIRST_SEARCH_HH
72 # include <mln/core/concept/iterator.hh>
73 # include <mln/core/concept/browsing.hh>
74 # include <mln/core/concept/graph.hh>
75 # include <mln/util/vertex.hh>
92 template <
typename E,
93 template <
typename T,
typename Seq>
class C >
94 class graph_first_search_t :
public Browsing< E >
97 typedef C< T_, std::deque<T_> > container_t;
99 template <
typename G,
typename F>
100 void operator()(
const Graph<G>&, F& f)
const;
105 # ifndef MLN_INCLUDE_ONLY
110 template <
typename T>
113 next(
const std::queue<T>& queue)
115 return queue.front();
118 template <
typename T>
121 next(
const std::stack<T>& stack)
126 template <
typename S>
141 template <
typename E,
142 template <
typename T,
typename Seq>
class C>
143 template <
typename G,
typename F>
146 graph_first_search_t<E, C>::operator()(
const Graph<G>& g_, F& f)
const
148 trace::entering(
"canvas::browsing::internal::graph_first_search");
150 const G& g = exact(g_);
151 mln_precondition(g.is_valid());
155 mln_vertex_iter(G) v(g);
157 if (f.to_be_treated(v.
id()))
161 f.new_component_from_vertex(v.id());
164 util::vertex<G> current_v = g.vertex(next(q));
165 f.process_vertex(current_v.id());
167 for (
unsigned nv = 0; nv < current_v.nmax_nbh_vertices(); ++nv)
168 if (f.to_be_queued(current_v.ith_nbh_vertex(nv)))
170 f.added_to_queue(current_v.ith_nbh_vertex(nv));
171 q.push(current_v.ith_nbh_vertex(nv));
178 trace::exiting(
"canvas::browsing::internal::graph_first_search");
181 # endif // ! MLN_INCLUDE_ONLY
192 #endif // ! MLN_CANVAS_BROWSING_INTERNAL_GRAPH_FIRST_SEARCH_HH