Repository navigation
Refresh a changed SortedKeyList item by its index - #268
Open
Aschenbath wants to merge 1 commit into
Open
Aschenbath wants to merge 1 commit into
Aschenbath wants to merge 1 commit into
Conversation
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.
Add
SortedKeyList.update_key(index)to refresh an occurrence after its comparison key changes and return its new index. It computes the key once, preserves the position when the neighbors still permit it, and moves within a block without rebuilding the positional index. Cross-block moves preserve the existing split/merge invariants; key extraction and comparisons complete before cached data is changed.Closes #181. The caller supplies the occurrence's index from before mutation; all other cached keys must remain valid, and comparison keys must be separate stable values. Equal-key positions are retained when no move is needed; moved values follow existing equal keys.
Python 3.12 and 3.10 each pass all 405 tests. All 38 added cases fail on the unchanged baseline; they cover identity, duplicates, negative/index-protocol indices, exception behavior, cached indexes, and 6,000 randomized updates. Sphinx with warnings as errors passes. Changed files pass Ruff format/lint, excluding the five existing B905 findings; the full baseline also has two unrelated formatting failures.
A seven-round local benchmark with 100,000 items and 10,000 updates measures update_key/remove-before-mutate+add/pop+add medians of 21.080/38.679/39.737 ms without movement, 28.010/35.240/40.011 ms within a block, and 48.548/37.252/41.621 ms across blocks. The gains are in the first two cases; cross-block moves remain slower in this workload.