27 #ifndef MLN_UTIL_GRAPH_HH
28 # define MLN_UTIL_GRAPH_HH
34 # include <mln/util/internal/graph_base.hh>
35 # include <mln/util/internal/graph_iter.hh>
36 # include <mln/util/internal/graph_nbh_iter.hh>
37 # include <mln/util/vertex.hh>
38 # include <mln/util/edge.hh>
39 # include <mln/util/ord_pair.hh>
45 namespace util {
class graph; }
56 struct data<util::graph>
58 typedef util::graph G;
59 typedef std::vector<std::vector<util::edge_id_t> > vertices_t;
60 typedef std::vector<util::ord_pair<util::vertex_id_t> > edges_t;
61 typedef std::set<util::ord_pair<util::vertex_id_t> > edges_set_t;
66 data(
unsigned nvertices);
76 edges_set_t edges_set_;
148 graph(
unsigned nvertices);
164 std::pair<vertex_id_t, vertex_id_t>
add_vertices(
unsigned n);
211 const std::vector<util::ord_pair<vertex_id_t> >&
edges()
const;
239 template <
typename G2>
255 # ifndef MLN_INCLUDE_ONLY
271 vertices_.resize(nvertices);
287 this->
data_ =
new mln::internal::data<util::graph>();
293 this->
data_ =
new mln::internal::data<util::graph>(nvertices);
306 data_->vertices_.resize(
data_->vertices_.size() + 1);
312 std::pair<vertex_id_t, vertex_id_t>
317 data_->vertices_.resize(
data_->vertices_.size() + n);
319 return std::make_pair(
v_nmax() - n,
327 mln_assertion(
has_v(id_v));
336 return data_->vertices_.size();
343 return id_v <
data_->vertices_.size();
350 mln_precondition(
has_v(id_v));
351 return data_->vertices_[id_v].size();
358 mln_precondition(
has_v(id_v));
361 return data_->vertices_[id_v][i];
368 mln_precondition(
has_v(id_v));
376 mln_precondition(
has_v(id_v));
391 mln_precondition(id_v1 != id_v2);
392 mln_precondition(
has_v(id_v1));
393 mln_precondition(
has_v(id_v2));
396 edge_data_t
edge(id_v1, id_v2);
418 data_->vertices_[
edge.first()].push_back(
id);
419 data_->vertices_[
edge.second()].push_back(
id);
430 const std::vector<util::ord_pair<vertex_id_t> >&
433 return this->
data_->edges_;
440 mln_assertion(e <
e_nmax());
448 return data_->edges_.size();
455 return id_e <
data_->edges_.size();
460 graph::edge(
const vertex_t& v1,
const vertex_t& v2)
const
462 mln_precondition(
has_v(v1));
463 mln_precondition(
has_v(v2));
470 std::swap(id_v1, id_v2);
472 for (
unsigned i = 0; i <
data_->vertices_[id_v1].size(); ++i)
473 if (
data_->edges_[
data_->vertices_[id_v1][i]].second() == id_v2)
484 mln_precondition(
has_e(id_e));
485 return data_->edges_[id_e].first();
492 mln_precondition(
has_e(id_e));
493 return data_->edges_[id_e].second();
500 mln_precondition(
has_e(id_e));
508 mln_precondition(
has_e(id_e));
519 template <
typename G2>
524 return g.id() == this->
id();
530 operator<<(std::ostream& ostr,
const graph& g)
532 mln_vertex_iter_(graph) v(g);
533 mln_vertex_nbh_edge_iter_(graph) e(v);
536 ostr <<
"v(" << v <<
") : ";
549 # endif // ! MLN_INCLUDE_ONLY
552 #endif // ! MLN_UTIL_GRAPH_HH