Repository navigation
minigraf-algorithms: add DFS, shortest path, topological sort, connected components - #15
Merged
Merged
Conversation
…connected components Closes #12. - Add `nodes()` to `GraphView` so whole-graph algorithms can see nodes with no outgoing edges. `EdgeList` keeps nodes in first-seen order, which gives stable results. - Add `depth_first`, `shortest_path` (unweighted, BFS), `topological_sort` (Kahn, returns an error on cycles), and `connected_components` (weakly connected). - Document each function with its time complexity. - Add EdgeList unit tests and live Minigraf tests for each algorithm. - Bump crate to 0.2.0 because the new trait method breaks outside `GraphView` implementations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018zSbkRnGmq7ekEJZZQtr4e
Plain `cargo build` and `cargo test` only cover the root package, so minigraf-algorithms and minigraf-schema were never tested in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018zSbkRnGmq7ekEJZZQtr4e
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.
Closes #12.
Summary
This PR adds four graph algorithms to
minigraf-algorithms. Each one is a free function that takes&impl GraphViewand runs in O(V + E).depth_first(graph, start)start, in depth-first (preorder) order. Likereachable, it leaves outstartunless a cycle leads back to it.shortest_path(graph, from, to)Option<Vec<Value>>with the fewest-hop path, both ends included.topological_sort(graph)Result<Vec<Value>>. Uses Kahn's algorithm. Returns an error that names a node in the cycle if the graph is cyclic.connected_components(graph)Breaking change:
GraphView::nodes()Topological sort and connected components must see every node, including nodes with no outgoing edges.
outgoing()alone cannot give that, soGraphViewnow has a requirednodes()method.EdgeListkeeps nodes in the order it first sees them. Ties in the sort and the order of components are the same on every run.GraphViewimplemented outside this repo must addnodes(). The crate is not on crates.io yet, so I bumped it to0.2.0.CI fix
The workflow ran plain
cargo buildandcargo test. These cover only the root package, sominigraf-algorithmsandminigraf-schemawere never tested in CI. Both commands now use--workspace.Tests
EdgeListunit tests. They cover cycles, self-loops, edge direction, and an empty graph.Minigrafdatabase.cargo test --workspacepasses locally. Clippy shows no warnings on the crate.Docs: each function has doc comments with its time complexity. The crate README has a new table of the algorithms and a note on implementing
GraphView.🤖 Generated with Claude Code
https://claude.ai/code/session_018zSbkRnGmq7ekEJZZQtr4e
Generated by Claude Code