Repository navigation
Add optimized key-range deletion to SortedDict - #263
Open
Aschenbath wants to merge 1 commit into
Open
Aschenbath wants to merge 1 commit into
Aschenbath wants to merge 1 commit into
Conversation
Aschenbath
added a commit
to Aschenbath/python-sortedcontainers
that referenced
this pull request
Nov 7, 2026
Combine PR grantjenks#263 at 76e9cae with only the three reviewed lint/format changes from PR grantjenks#259 at a7d452d. Preserve every existing workflow file byte-for-byte. This fork-only validation commit retains the full original checks and Ubuntu Python matrix.
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.
Deleting a key range from
SortedDictcurrently requires repeated per-key removal or conversion to positional indices. Addrange_del(minimum=None, maximum=None, inclusive=(True, True)), following the API proposed in #180, to delete the range directly by block coordinates.The implementation removes complete interior blocks, rebalances boundary fragments, and preserves cached sort keys. It avoids constructing the positional index and searching again for every removed key. Bounds follow
irange, including key functions and equal comparison keys; empty ranges leave the block layout and positional cache intact. The method returnsNone.Deletion is documented as worst-case
O(k + m + n/m), including movement of the flat block array, withO(k + m)temporary space. In a local million-key benchmark, deleting the middle 100,000 plain keys took 13.37 ms, versus 113.80 ms for the loop and 366.76 ms for view slicing. Deleting 900,000 keys took 115.30 ms, versus 911.71 ms and 127.37 ms. Single-key deletion has extra fixed overhead: 135 us versus 47 us for the loop and 258 us for slicing. Measurements are medians of five fresh-map runs on Windows / CPython 3.12.12, excluding construction and verifying every result.Validation:
Fixes #180.
AI assistance: OpenAI Codex assisted with implementation, tests and documentation; a separate Codex reviewer checked the change and ran an independent oracle. No human code review is claimed.