Repository navigation
fix: reserve CSR storage when building from sorted edges - #671
Merged
Merged
Conversation
|
Boost dependency footprint vs Header-inclusion weights (graph files pulling each direct dependency in): No header-inclusion-weight changes. Transitive Boost modules: 47 → 47 (0) |
|
Compiler-warning counts vs
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Becheler
force-pushed
the
fix/csr-sorted-reserve
branch
2 times, most recently
from
October 28, 2026 09:56
a694dd5 to
9516e2d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Building a CSR graph from sorted edges without numedges used to reserve the edge storage anyway when the range is random access, since the count is then available in O(1).
Regression: commit 50bc92b (2009, "Refactored CSR graph code to get ready for bidirectional support") moved that count from the constructors into
assign_from_sorted_edgesand broke the reservation in both overloads. The overload without edge properties never computes the count. The overload with edge properties computes it and then still reserves the caller's zero. So, the column vector, and the edge property vector in the second overload grow by repeated reallocation. They end with capacity up to about 2x the edge count, and in the worst case peak at about 3x during the last reallocation. Nobody noticed because reserve does not change the resulting graph and no test checked capacity.What this PR does
Both overloads now reserve the computed edge count when the caller passes zero. A new test in csr_graph_test.cpp builds directed and bidirectional graphs with and without an edge property iterator, and checks that the column capacity equals the number of edges. Forward and input iterators are unaffected, and so are callers that pass an explicit edge count.
Before submitting
developbranch.Kind of change
Tick exactly one. Each kind is reviewed differently, so mixing them in one PR makes the diff difficult to review (why).
Change category