I need to map vertices in a Boost Graph to an unsigned integer. I learned from related posts on this site (1, 2) that the proper way to do this is to create a custom vertex class.
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;
However, according to the documentation (Iterator and Descriptor Stability/Invalidation), the vertex descriptors can become invalid, which means that I should not store them to map the vertices.
Since I have my custom vertex class + .index, this should not be a problem.
But: How do I retrieve the vertex_descriptor for a specific index at a later time? And how can I do that without linear search?
Or is there a better way to keep a persistent id for each vertex than such a custom vertex class?