[BGL] boost::add_vertex - add unique vertexes to graph

Hi, Currently I externally check if vertex exist in graph. But it is look like boost::add_vertex can check internally if vertexes are unique. if (optional<vertex_descriptor> v = g.vertex_by_property(get_property_value(p, vertex_bundle))) return *v; Could you send me any example where boost::add_vertex just return already created vertex (line: "return *v") instead of create new one? boost_1_39_0\boost\graph\detail\adjacency_list.hpp contain: 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; } Best regards, Mariusz

Currently I externally check if vertex exist in graph. But it is look like boost::add_vertex can check internally if vertexes are unique. if (optional<vertex_descriptor> v = g.vertex_by_property(get_property_value(p, vertex_bundle))) return *v;
Could you send me any example where boost::add_vertex just return already created vertex (line: "return *v") instead of create new one?
In 1.39, there is a class called named_graph allows you to do something like this, but it's completely undocumented and I'm not sure how to use it. In trunk, there is a graph adaptor called labeled_graph (also undocumented), that can be used to maintain a mapping of elements to vertices, but it doesn't work with interior or bundled vertex properties yet. Otherwise, your best bet is to simply keep passing around a map of property to vertex. Andrew Sutton andrew.n.sutton@gmail.com
participants (2)
-
Andrew Sutton
-
Mariusz Kwiczala