Repository navigation
Refactor Prim heap index handling - #112
Open
pruthvirajgojare-source wants to merge 2 commits into
Open
pruthvirajgojare-source wants to merge 2 commits into
pruthvirajgojare-source wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Description
Refactors Prim's minimum spanning tree priority queue heap indexing to reduce duplicated arithmetic and simplify the downward heap adjustment. The change is intended to improve readability while preserving behavior.
Related Issue
No related issue identified.
Fixes: N/A (no related issue)
Type of Change
Changes Made
get_child_right_positionnow derives its result fromget_child_left_position(position) + 1._bubble_downchooses the smaller available child once before swapping, avoiding repeated child-weight/index handling.work/R23-T048/._bubble_downcomplexity decreased from 7 to 4; file-wide maximum remainsprims_algoat 8 (below Ruff's default threshold of 10).Screenshots / Recordings
Not applicable; no UI changes.
Testing
uvx ruff check graphs/minimum_spanning_tree_prims2.py— passed.uvx ruff check --select C90 graphs/minimum_spanning_tree_prims2.py— passed.uv run pytest graphs/minimum_spanning_tree_prims2.py— passed, 5 pytest items.uv run python -m doctest -v graphs/minimum_spanning_tree_prims2.py— passed, all 24 doctests.uv run pytest graphs/minimum_spanning_tree_prims2.py --cov=graphs.minimum_spanning_tree_prims2 --cov-report=term— passed, coverage 95% (baseline 93%).uvx ruff format --check graphs/minimum_spanning_tree_prims2.py— passed.Checklist
Additional Notes
The task branch includes the code change and evidence files. A separate local
upstream/R23-T048branch contains only the code change; no upstream PR was opened. Baseline coverage was 93% (126 statements, 9 missed); after refactoring it is 95% (116 statements, 6 missed).