filtered_graph: num_vertices is an index bound, not a count
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 402
- Fork
- 251
- Merge medio
- 1g 9h
- PR unite (30g)
- 38
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di boostorg/graph
-
Good first issues: start contributing to Boost.Graph hereForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabeginner friendly
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
boostorg/graph#593 · 63 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
CMake < 3.10 failsApertainfra priority: high
Difficoltà 3/5 Mezza giornata Idoneità per principianti 45/100
boostorg/graph#688 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
I maintainer di solito rispondono entro 1 giorno
-
algorithm
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
Trivial Minimum Cycle Ratio FailingForse di nuovo libera @Becheler l’ha presa 46 giorni fa e non c’è nessuna pull request aperta. Apertaalgorithm
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
boostorg/graph#599 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di boostorg/graph
Issue simili
-
agent:WSL code-review linux pri:medium refactoring
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
kind/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
psi29a/d2decomped#691 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
CachyOS/packageinstaller#144 ·
I maintainer di solito rispondono entro 1 giorno
-
(S1 - Need confirmation)
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CleverRaven/Cataclysm-DDA#89715 ·
I maintainer di solito rispondono entro 1 giorno