在 Boost Graph Library 中,为什么添加边会使边迭代器无效(以及其他问题)?

In the Boost Graph Library, why does adding an edge invalidate Edge iterators (and other questions)?

关于 BGL documentation 标签 "Summary of Descriptor and Iterator Invalidation" 中图表的几个问题:

  1. 为什么添加边会使边和邻接迭代器失效;为什么 add_edge() 行的每一列不是 "OK"? in/out 边缘列表不会简单地附加吗?
  2. 如果图是有向的,为什么删除边只会使边迭代器无效;为什么第二行的倒数第二列不是简单的 "EL=vecS"?在无向图的情况下,不会删除一条边将其从两个边列表(一个用于源顶点,一个用于目标顶点)中删除,这会使这两个列表中的迭代器无效?

谢谢!

所有这些效果都来自通常的 Iterator invalidation rules

  1. Why does adding an edge invalidate the edge and adjacency iterators; why isn't every column of the add_edge() row "OK"? Wouldn't the in/out edge lists simply be appended?

是的,它们会被附加。并且,看到他们可能会重新分配这样做,他们使迭代器无效。

  1. Why does removing an edge only invalidate an edge iterator if the graph is directed

矩阵中的符号有点令人困惑。

文档:“此操作会导致指向边 (u,v) 的任何未完成的边描述符或迭代器变得无效。此外,如果 OutEdgeList 选择器是 vecS 然后此操作将使指向顶点 u 和顶点 v 的边列表中的任何迭代器在无向和双向情况下无效。此外,对于有向图,这会使任何 edge_iterator."

所以你误读了:它不仅使 "if the graph is directed" 无效。在无向和双向情况下,它 使指向目标顶点 (v) 的边列表的任何迭代器无效。如果您了解后边的存储方式,这是有道理的。