简体   繁体   English

Boost 图——将顶点/边存储为 std::list 并随后随机访问关联的顶点/边属性 map

[英]Boost graph -- storing vertices / edges as std::list and subsequent random access of associated vertex / edge property map

Consider:考虑:

typedef adjacency_list<
    listS, //out edges stored as std::list
    listS, //verteices stored as std::list
    directedS,
    property<vertex_name_t, std::string>,
    property<edge_weight_t, double>
> user_graph;

Storage of edges and vertices as std::list precludes random access via [index] .将边和顶点存储为std::list会阻止通过[index]进行随机访问。

Consider further that property maps are defined so.进一步考虑属性映射是这样定义的。

typedef property_map<user_graph, vertex_name_t>::type name_map_t;
typedef property_map<user_graph, edge_weight_t>::type weight_map_t;

user_graph g;
name_map_t name_map = get(vertex_name, g);
weight_map_t weight_map = get(edge_weight, g);

Even though random access of actual edges/vertices is not possible via [index] , is it guaranteed that access to the name of a vertex and weight of an edge are efficient and fast under random access like so:即使无法通过[index]随机访问实际边/顶点,是否可以保证在随机访问下访问顶点的名称和边的权重是高效且快速的,如下所示:

graph_traits<user_graph>::vertex_iterator vi, vi_end;
for(tie(vi, vi_end)=vertices(g); vi != vi_end; ++vi)
    cout<<"Name of vertex is "<<name_map[*vi];//Question is, is this efficient given storage of vertices as std::list

Part of my confusion comes from general std::map characteristic that it too does not support random access (See here )我的部分困惑来自一般的std::map特性,它也不支持随机访问(见这里

Is it the case that whether vertices are stored as std::vector or std::list or std::set , regardless, access to its property maps via vertex descriptors using some_map[vertex_descriptor] or some_map[*vertex_iterator] is always guaranteed to be efficient (constant time)?是否顶点存储为std::vectorstd::liststd::set ,无论如何,通过使用some_map[vertex_descriptor]some_map[*vertex_iterator]的顶点描述符访问其属性映射总是保证高效(恒定时间)?

is it guaranteed that access to the name of a vertex and weight of an edge are efficient and fast under random access like so:是否保证在随机访问下访问顶点的名称和边的权重是高效且快速的,如下所示:

Yes.是的。 The properties are actually stored inline with the vertex/edge node .这些属性实际上与 vertex/edge node内联存储。 A descriptor is effectively a type erased pointer to that node.描述符实际上是指向该节点的类型擦除指针。 name_map[*vi]->name ends up inlining to something like get<N>(*vi_cast_to_nodeptr) if you imagine the property storage as a kind of tuple with a get<> accessor.如果您将属性存储想象成一种带有get<>访问器的元组,那么name_map[*vi]->name最终会内联到类似get<N>(*vi_cast_to_nodeptr)的内容。

Part of my confusion comes from general std::map characteristic that it too does not support random access我的部分困惑来自一般的 std::map 特性,它也不支持随机访问

Property maps are not like std::map;属性映射不像 std::map; They may be consecutive, they may be node-based, ordered, unordered, or even calculated.它们可能是连续的,它们可能是基于节点的、有序的、无序的,甚至是计算的。 In fact Boost Property Map maybe closer to the concept of a Lense in some functional programming languages.事实上,Boost Property Map在某些函数式编程语言中可能更接近于镜头的概念。 It is a set of functions that can be used to model (mutable) projections for a given key type.它是一组函数,可用于给定密钥类型的 model(可变)投影。

See also:也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM