Boost logo

Boost Users :

Subject: Re: [Boost-users] [graph]
From: liquid (kj_at_[hidden])
Date: 2009-04-21 12:14:05


Andrew Sutton pisze:
>
> Does "add_vertex" check the existence of added vertices of given
> index? No, it doesn't.
> Or I do something wrong.
>
>
> For a short answer: never.
>
Well, it seemed that sometimes yes.

I looked at the piece of code of add_vertex in a boost/graph header file:

    template <class Graph, class Config, class Base>
    inline typename Config::vertex_descriptor
    add_vertex(const typename Config::vertex_property_type& p,
               vec_adj_list_impl<Graph, Config, Base>& g_) {
      typedef typename Config::vertex_descriptor vertex_descriptor;
      Graph& g = static_cast<Graph&>(g_);
      if (optional<vertex_descriptor> v
            = g.vertex_by_property(get_property_value(p, vertex_bundle)))
        return *v;
      typedef typename Config::stored_vertex stored_vertex;
      g.m_vertices.push_back(stored_vertex(p));
      g.added_vertex(g.m_vertices.size() - 1);
      return g.m_vertices.size() - 1;
    }

So, with property defined as follows
property_type: typedef property<vertex_index_t,string> VIndex;

Undoubtedly, above add_vertex function searches vertex by properties and
should return descriptor of found vertex. Indeed, it doesn't.

I'm a little bit confused.

> For a longer answer... It looks like vertices are dynamically allocated
> and the vertex set (listS, setS, etc.) stores pointers to those
> vertices. In the case of associate containers, the key_type is just the
> pionter value. In otherwords, add_vertex will never look for a previous
> instance of the vertex.
>
> Andrew Sutton
> andrew.n.sutton_at_[hidden] <mailto:andrew.n.sutton_at_[hidden]>

Regards
liquid


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net