Fix findCycles missing self-loops created with named edges#235
Open
chatman-media wants to merge 1 commit into
Open
Fix findCycles missing self-loops created with named edges#235chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
findCycles checked for a single-node component's self-loop via graph.hasEdge(v, v), which only matches the default (unnamed) edge. A self-loop added as a named edge in a multigraph (setEdge(v, v, label, name)) was therefore missed, so findCycles returned no cycle for such a node. Use graph.outEdges(v, v), which returns every edge between v and itself regardless of edge name, so any self-loop is detected. Fixes dagrejs#111
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.
Fixes #111.
findCyclesdecides whether a single-node strongly-connected component is a cycle by callinggraph.hasEdge(v, v). That overload only matches the default (unnamed) edge, so a self-loop added as a named edge in a multigraph (setEdge(v, v, label, name)) is missed and the node is wrongly reported as cycle-free.Switched the check to
graph.outEdges(v, v), which returns every edge betweenvand itself regardless of name, so any self-loop is detected. Behaviour for unnamed self-loops is unchanged.Repro (before this PR returns
[]):Added a regression test (fails without the fix). Full suite (256 tests), typecheck and lint all pass.