在Boost Graph库中,为什么添加边会使Edge迭代器无效(以及其他问题)? [英] In the Boost Graph Library, why does adding an edge invalidate Edge iterators (and other questions)?

查看:152
本文介绍了在Boost Graph库中,为什么添加边会使Edge迭代器无效(以及其他问题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BGL文档中有关图表的一些问题标为描述符和迭代器无效摘要":

A few questions about the chart in the BGL documentation labeled "Summary of Descriptor and Iterator Invalidation":

  1. 为什么添加边缘会使边缘和邻接迭代器无效;为什么add_edge()行的每一列都不确定"?进/出边缘列表是否仅会附加?
  2. 为什么移除边仅在有向图的情况下才使边迭代器无效;为什么第二行中的倒数第二列不是简单的"EL = vecS"?在无向图的情况下,是否要删除一条边,是否要将其从两个边列表中删除(一个用于源顶点,一个用于目标顶点),这会使两个列表中的迭代器都无效?

谢谢!

推荐答案

所有这些效果均来自通常的迭代器无效规则

All of these effects follow from the usual Iterator invalidation rules

  1. 为什么添加边缘会使边缘和邻接迭代器无效;为什么add_edge()行的每一列都不确定"?进/出边缘列表是否仅会附加?

是的,它们将被附加.而且,看到他们可能会重新分配,他们使迭代器无效.

Yes they would be appended. And, seeing that they might reallocate doing so, they invalidate iterators.

  1. 为什么移除边缘只会在有向图的情况下使边缘迭代器无效

矩阵中的符号有点混乱.

The notation in the matrix is more than a little confusing.

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

Docs: "This operation causes any outstanding edge descriptors or iterators that point to edge (u,v) to become invalid. In addition, if the OutEdgeList selector is vecS then this operation will invalidate any iterators that point into the edge-list for vertex u and also for vertex v in the undirected and bidirectional case. Also, for directed graphs this invalidates any edge_iterator."

所以您读错了:它不仅使如果图形是有向的"无效.在无向和双向情况下,它使指向目标顶点(v)的边列表的所有迭代器无效.如果您意识到后边缘的存储方式,这是有道理的.

So you misread: it doesn't only invalidate "if the graph is directed". It also invalidates any iterators that point into the edge-list for the target vertex (v) in the undirected and bidirectional case. This makes sense if you realize how the back-edged are stored.

这篇关于在Boost Graph库中,为什么添加边会使Edge迭代器无效(以及其他问题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆