filtered_graph: num_vertices is an index bound, not a count
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with the two num_vertices call sites in include/boost/graph/connected_components.hpp (lines 72-73 and 106-108) to see where the value is used as a count versus an index bound. Then check the filtered-graph docs in doc/modules/ROOT/pages/adaptors/filtered_graph.adoc and the open issues #231 and #627. Done means agreeing on the proposed API split with maintainers; the issue itself lists the design choice as open, so a newcomer should not start on the library-wide change.
由索引模型根据 Issue 内容生成。
描述
num_vertices(g) is used for two different things in BGL:
- as a vertex count (emptiness checks, loop bounds, sampling)
https://github.com/boostorg/graph/blob/ddce215b8b7adafd22927ea508b5991ade7c9064/include/boost/graph/connected_components.hpp#L72-L73 - and as an upper bound on vertex indices to size property arrays.
https://github.com/boostorg/graph/blob/ddce215b8b7adafd22927ea508b5991ade7c9064/include/boost/graph/connected_components.hpp#L106-L108
[!NOTE]
This works today because filtering doesn't renumber vertices: a kept vertex keeps its index from the base graph, so indices still go up to the base graph's size.filtered_graphforwardsnum_verticesandnum_edgesto the base graph, so any array sized withnum_vertices(fg)is large enough for every index still in use. The price is thatnum_verticesno longer means "how many verticesvertices(fg)yields".
// base graph has vertices 0 1 2 3 4, the filter keeps 0 2 4
std::vector<color> color_map(num_vertices(fg));
// num_vertices(fg) is 5, so color_map[4] is valid
// if it returned 3, color_map[4] would be out of bounds
color_map[get(vertex_index, fg, 4)] = ...;
Bug: Since num_vertices(fg) doesn't match what vertices(fg) yields, every algorithm that uses it as a count can go wrong once vertices are filtered out:
connected_componentsreturnsmax() + 1on an empty filtered graph: #231sequential_vertex_coloringread out of bounds: #627, fixed in #630random_vertex/random_edgecan advance past the end of the filtered rangevf2_sub_graph_isonever reports a mapping on a vertex-filtered graph. The docs say it was patched to usestd::distance, but the fix in #282 was never merged.scale_graphandwarren_transitive_closuredereference or step past the end when every vertex is filtered outstoer_wagner_min_cuttakes its phase count fromnum_vertices
Users hit this too: Rosetta, Hyperscan and IfcOpenShell all carry comments and workarounds for it, and BGL has its own count_vertices in isomorphism.hpp.
Proposal
- Add
vertex_index_bound(g)/edge_index_bound(g)(names TBD), defaulting tonum_vertices(g)/num_edges(g). Nothing changes for existing graphs. - Move algorithms to the bound when sizing property storage, and keep
num_verticesfor counting. - Then make
filtered_graph'snum_vertices/num_edgesreturn the real count (O(V) or cached, O(1) when the predicate iskeep_all).
Step 3 silently breaks user code that does std::vector<T> v(num_vertices(fg)) on a vertex-filtered graph and indexes it by vertex index. It compiles and then writes out of bounds. A search of public code found only a handful of such cases (bark, two OpenCV books, a BGL test), but it should still go with a release that already breaks things, plus a loud release note.
For #231 itself, fixing the call sites is enough.
- 主要语言
- C++
- 星标
- 402
- 派生
- 251
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
boostorg/graph 的其他 Issue
-
Good first issues: start contributing to Boost.Graph here可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭beginner friendly
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
infra priority: high
难度 3/5 半天 新手友好度 45/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 15/100
维护者通常 1 天内回复
-
algorithm
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
-
Trivial Minimum Cycle Ratio Failing可能重新可做 @Becheler 于 46 天前认领,目前没有进行中的 PR。 未关闭algorithm
难度 3/5 1-2 天 新手友好度 68/100
boostorg/graph#599 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
agent:WSL code-review linux pri:medium refactoring
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
kind/enhancement
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
psi29a/d2decomped#691 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
CachyOS/packageinstaller#144 ·
维护者通常 1 天内回复
-
(S1 - Need confirmation)
难度 2/5 1-3 小时 新手友好度 62/100
CleverRaven/Cataclysm-DDA#89715 ·
维护者通常 1 天内回复