Conversation
…s do when the graph is disconnected prim was the only algorithm not re-exported from the prelude, so `use pathfinding::prelude::*` reached kruskal but not prim, and callers had to name pathfinding::undirected::prim::prim in full. The two also disagree on disconnected input without saying so. prim grows outwards from one node and spans only that component; kruskal spans every component and returns a forest. Both simply said "minimum-spanning-tree", which is true of neither in that case without qualification. Document the difference on both, with a runnable example.
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.
Two small things about
prim, found while looking through the library.primis missing from the preludeEvery other algorithm is re-exported there;
primis not. So this does not compile:and callers have to write
pathfinding::undirected::prim::priminstead, whilekruskal, sitting right next to it insrc/undirected/, works from the prelude. I ran into this writing a throwaway test, which is how it turned up. One line insrc/lib.rs.The two MST functions disagree on disconnected graphs, silently
primgrows outwards from the first endpoint of the first edge, so it spans only that component.kruskalsorts all edges and unions, so it spans every component and returns a forest.Both behaviours are reasonable, and neither is a bug. The problem is that both doc comments just say "minimum-spanning-tree", which does not distinguish them, so a caller who swaps one for the other on a disconnected graph gets a quietly different answer. This documents the difference on both sides, with a runnable example on
prim.No behaviour change; docs and one re-export.