Skip to content

Clarify connected_components candidate vertex semantics - #841

Merged
samueltardieu merged 1 commit into
mainfrom
copilot/840-clarify-starting-nodes
Sep 22, 2026
Merged

samueltardieu merged 1 commit into
mainfrom
copilot/840-clarify-starting-nodes

Conversation

Copilot AI commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

connected_components was easy to misread as a recursive graph traversal from the provided inputs. In practice, the input slice defines the candidate vertices whose neighbour sets are merged; neighbours discovered from those vertices are included in the result but are not recursively expanded unless they are also present in the input.

  • API naming

    • Rename the input parameter from starts to candidates to reflect its actual role in the algorithm.
  • Documentation

    • Update the API docs to state that only candidate vertices are queried via neighbours.
    • Explicitly call out that returned neighbours are grouped with their candidate vertex but are not explored further unless they also appear in candidates.
  • Tests

    • Rename the relevant test and tighten its wording so the expected non-recursive behaviour is clear from the test itself.
let components = connected_components(&[0, 3], |node| match node {
    0 => [1].as_slice().iter().copied(),
    1 => [0, 2].as_slice().iter().copied(),
    2 => [1, 3].as_slice().iter().copied(),
    3 => [2].as_slice().iter().copied(),
    _ => unreachable!(),
});

In this shape, 0 and 3 are the candidate vertices. Their neighbour sets are merged into a single component, but 1 and 2 are not queried unless they are also included in the candidate list.

Close #840

Co-authored-by: samueltardieu <44656+samueltardieu@users.noreply.github.com>
Copilot AI changed the title Clarify connected_components candidate vertices Clarify connected_components candidate vertex semantics Sep 22, 2026
Copilot AI requested a review from samueltardieu September 22, 2026 21:16
@samueltardieu
samueltardieu marked this pull request as ready for review September 22, 2026 21:17
@samueltardieu
samueltardieu added this pull request to the merge queue Sep 22, 2026
@github-actions

Copy link
Copy Markdown

📊 iai-callgrind Benchmark Results

➡️ 20 Unchanged (within ±0.1%)

Click to expand
Benchmark Instructions
iai_algos::corner_to_corner_astar 155,711
iai_algos::corner_to_corner_bfs 2,515,366
iai_algos::corner_to_corner_bfs_bidirectional 2,787,420
iai_algos::corner_to_corner_dfs 3,345,644
iai_algos::corner_to_corner_dijkstra 3,077,225
iai_algos::corner_to_corner_fringe 103
iai_algos::corner_to_corner_idastar 81,629
iai_algos::corner_to_corner_iddfs 3,712,137
iai_algos::no_path_astar 14
iai_algos::no_path_bfs 159
iai_algos::no_path_bfs_bidirectional 2,658,317
iai_algos::no_path_dfs 14
iai_algos::no_path_dijkstra 3,047,614
iai_algos::no_path_fringe 14
iai_edmondskarp::wikipedia_example_dense 22,382
iai_edmondskarp::wikipedia_example_sparse 46,083
iai_kuhn_munkres::kuhn_munkres_size_128 4,211,200
iai_kuhn_munkres::kuhn_munkres_size_32 239,050
iai_kuhn_munkres::kuhn_munkres_size_64 1,199,842
iai_separate_components::bench_separate_components 16,464,323

✅ All benchmarks unchanged


iai-callgrind measures instructions executed, which is deterministic and not affected by system load.

Merged via the queue into main with commit 3e684ca Sep 22, 2026
12 checks passed
@samueltardieu
samueltardieu deleted the copilot/840-clarify-starting-nodes branch September 22, 2026 21:23
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.

connected_components does not recursively find nodes and thus connections

2 participants