为什么使用 vecS 作为 OutEdgeList 模板参数的提升 adjacency_list 会使遍历中的边无效?

Why does a boost adjacency_list using vecS as OutEdgeList template parameter invalidate edges on traversal?

我正在阅读有关 adjacency_list and the impact choosing the graph type 的文档,内容涉及内存消耗、big-O 运行时和描述符稳定性。

引用第一个link:

The following table summarizes which operations cause descriptors and iterators to become invalid. In the table, EL is an abbreviation for OutEdgeList and VL means VertexList. The Adj Iter category includes the out_edge_iterator, in_edge_iterator, and adjacency_iterator types.
A more detailed description of descriptor and iterator invalidation is given in the documentation for each operation.

我知道如果使用 vecS 作为 VertexList,那么在 remove_vertex() 上所有顶点描述符都将被调整,以便它们仍然是连续的。

我不明白为什么使用 vecS 显然会导致边缘迭代使边缘描述符无效。

我对 table 的理解是否正确,因为它是说“如果您在 adjacency_list 图上使用 vecS 作为边缘列表类型,那么 directedS 那么你不能稳定地迭代边缘,因为迭代它们会使边缘迭代器和边缘描述符无效"?

如果我理解正确,请解释为什么会这样。如果我理解有误,请说明使用vecS for Edge List的实际效果。
谢谢。

正如您所怀疑的那样,您误读了它。

令人困惑的是“Edge Iter”、“Vertex Iter”和“Adj Iter”列是“Iterator”的缩写,而不是“iteration”。

单纯的迭代行为永远不会改变 adjacency_list,因此不能使描述符或迭代器无效。

有些图模型中的描述符比迭代器(迭代器)多 stable。这实际上是描述符概念的关键原因。任何具有引用稳定性的容器选择器(即 node-based containers) 自然会具有迭代器稳定性(仅使迭代器无效到已删除的节点)。

table 很有用,因为对于“immutable”(或很少更改,query-often)的性能,可以通过选择连续存储(如 vecS)和他们自然会施加更多限制性的无效规则(例如,向量可能会重新分配,这 使 所有迭代器无效,但描述符可能会保持 stable 到 modification/insertion 的索引).

提示

要对基本失效问题进行原始 compile-time 检查,请考虑通过 const 引用获取图表。这将消除 off-chance 的意外修改。当然,在某些情况下,您真的想走边缘(为了性能)您想要对图形进行修改,并且您必须 per-use 文档以确切了解适用于该修改的无效规则。