Skip to content

fix(detect-cycle): add JSDoc return type and improve early-exit comments in detectUndirectedCycle#2111

Open
gb3335 wants to merge 1 commit intotrekhleb:masterfrom
gb3335:patch-1
Open

fix(detect-cycle): add JSDoc return type and improve early-exit comments in detectUndirectedCycle#2111
gb3335 wants to merge 1 commit intotrekhleb:masterfrom
gb3335:patch-1

Conversation

@gb3335
Copy link

@gb3335 gb3335 commented Mar 4, 2026

Closes #2057

Summary

Addresses issue #2057: Incorrect Cycle Path Construction in detectUndirectedCycle

Changes

  • Added @return {Object|null} JSDoc tag documenting the cycle object structure and return type
  • Improved inline comments explaining the early exit behavior via allowTraversal
  • Added a note about disconnected graph limitation when starting DFS from first vertex
  • Clarified cycle object representation with more descriptive comments

Notes

The early exit mechanism was already present but undocumented. The allowTraversal callback returns false when a cycle is detected, preventing unnecessary traversal of remaining graph edges — which improves efficiency as described in the issue.

The cycle return value remains an object (not an array) to maintain backward compatibility with existing tests and consumers.

…comments

Addresses issue trekhleb#2057: Incorrect Cycle Path Construction in detectUndirectedCycle

- Added @return JSDoc tag documenting the cycle object structure
- Improved inline comments explaining the early exit behavior via allowTraversal
- Added note about disconnected graph limitation in DFS start comment
- Clarified cycle object representation with more descriptive comments

The early exit mechanism was already present but undocumented. The allowTraversal
callback returns false when a cycle is detected, preventing unnecessary traversal
of remaining graph edges, which improves efficiency as described in the issue.
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.

Incorrect Cycle Path Construction in detectUndirectedCycle

1 participant