【发布时间】:2013-05-24 13:25:19
【问题描述】:
我需要将 Boost Graph 中的顶点映射到无符号整数。我从这个网站上的相关帖子(1,2)中了解到,正确的方法是创建一个自定义顶点类。
struct Vertex { uint32_t index; };
typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::directedS, Vertex> BoostGraphType;
typedef BoostGraphType::vertex_descriptor vertex_desc;
// now i can use
BoostGraphType g;
vertex_desc vd = boost::add_vertex(g);
g[vd].index = magic;
但是,根据文档 (Iterator and Descriptor Stability/Invalidation),顶点描述符可能会变得无效,这意味着我不应该存储它们来映射顶点。
由于我有我的自定义顶点类 + .index,这应该不是问题。
但是:我以后如何检索特定索引的 vertex_descriptor?如果没有线性搜索,我怎么能做到这一点?
或者有没有比这样的自定义顶点类更好的方法来为每个顶点保留一个持久的 id?
【问题讨论】:
标签: performance boost boost-graph