Skip to content

Refresh a changed SortedKeyList item by its index - #268

Open
Aschenbath wants to merge 1 commit into
grantjenks:masterfrom
Aschenbath:fix/big20-20261123-bde6-sortedcontainers-update-key
Open

Aschenbath wants to merge 1 commit into
grantjenks:masterfrom
Aschenbath:fix/big20-20261123-bde6-sortedcontainers-update-key

Conversation

@Aschenbath

Copy link
Copy Markdown

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.

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.

Feature request: update element key

1 participant