perf: single-pass pop_first/pop_last and remove cases 2a/2b#417
Draft
sasa-tomic wants to merge 1 commit intomainfrom
Draft
perf: single-pass pop_first/pop_last and remove cases 2a/2b#417sasa-tomic wants to merge 1 commit intomainfrom
sasa-tomic wants to merge 1 commit intomainfrom
Conversation
Replace the double-traversal pattern in pop_first/pop_last with single-pass remove_leftmost/remove_rightmost methods. Previously, pop_last would walk the rightmost spine to find the max key (loading ~4 nodes), then walk the same spine again via remove_helper to delete it (loading ~4 more nodes). The single-pass approach descends once, handling rebalancing (rotation/merge) during descent. Also fix the EXC-1034 TODO in remove_helper cases 2a/2b: replace get_max + remove_helper with remove_rightmost, and get_min + remove_helper with remove_leftmost. Expected improvement: ~50% fewer load_node calls for pop operations, plus eliminates redundant binary searches on the descent path.
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.
Summary
pop_last/pop_firstwith single-passremove_rightmost/remove_leftmostpop_lastcalledget_max(walks rightmost spine, ~4 node loads) thenremove_helper(walks from root again, ~4 more node loads). Now: single descent, handling rotation/merge during the walkremove_helpercases 2a/2b: replaceget_max + remove_helper(predecessor)withremove_rightmost(left_child), andget_min + remove_helper(successor)withremove_leftmost(right_child)Expected improvement: ~50% fewer
load_nodecalls for pop operations on a depth-4 tree (4 loads vs 8), plus eliminates 4 binary searches per operation.