Skip to content

Hand a graph's nodes back in id order - #252

Merged
Gonzalo-Mier merged 2 commits into
Fields2Cover:developfrom
u33549:dev/umutc/v2.1.0-devel/graph2d-node-order
Sep 22, 2026
Merged

Gonzalo-Mier merged 2 commits into
Fields2Cover:developfrom
u33549:dev/umutc/v2.1.0-devel/graph2d-node-order

Conversation

@u33549

@u33549 u33549 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Graph2D::getNodes() walked the unordered_map the nodes are kept in, so the
vector came back in hash order: not the order the ids were handed out in, and not
the same order on another build. The ids getEdges() reports index exactly that
vector, so a caller resolving an edge through it joined the wrong pair of points --
silently, and differently on another machine.

Measured on a visibility graph over a real field: of 1911 edges, 933 appeared to
run through the crop; resolved in id order, 2.

Ids are dense over 0..numNodes()-1 because they are handed out as the node count
at insertion and nodes are never erased, so the lookup cannot throw.

Adds a test that the ids getEdges() reports index the vector getNodes() returns.

getNodes() walked the unordered_map the nodes are kept in, so the vector came
back in hash order: not the order the ids were handed out in, and not the same
order on another build. The ids getEdges() reports index exactly that vector,
so a caller resolving an edge through it joined the wrong pair of points --
silently, and differently on another machine.

Measured on the bench's visibility graph: of 1911 edges, 933 appeared to run
through the crop; resolved in id order, 2. Ids are dense over 0..numNodes()-1
because they are handed out as the node count at insertion and nodes are never
erased, so the lookup cannot throw.
Copilot AI lite review requested due to automatic review settings September 18, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Fix Graph2D::getNodes() so the returned vector is ordered by node ID, allowing edge IDs to correctly index the corresponding nodes.

Changes:

  • Build the node vector by iterating dense IDs through index_to_nodes_.
  • Document the ordering contract in Graph2D.
  • Add tests covering ordered nodes and empty graphs.
  • Record the fix in the changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/fields2cover/types/Graph2D.cpp Returns nodes in ID order with reserved capacity.
include/fields2cover/types/Graph2D.h Documents the getNodes()[i] ordering guarantee.
tests/cpp/types/Graph2D_test.cpp Verifies ID-to-node ordering and empty-graph behavior.
CHANGELOG.md Documents the corrected node ordering behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Gonzalo-Mier
Gonzalo-Mier merged commit 61cc2b1 into Fields2Cover:develop Sep 22, 2026
69 of 70 checks passed
@Gonzalo-Mier

Copy link
Copy Markdown
Member

Thank you for finding all this issues @u33549

@u33549
u33549 deleted the dev/umutc/v2.1.0-devel/graph2d-node-order branch September 22, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants