Repository navigation
feat(ts): translate a B-tree's extract_if, with its Debug - #557
Merged
Merged
Conversation
Quest-Claim: 4a5195755169d3a0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t comparing keys Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ract-if # Conflicts: # ts/MIGRATE.md
kixelated
marked this pull request as ready for review
November 4, 2026 00:13
|
This run was cancelled before it finished. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 33 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.

Problem
rust2-ts refused
BTreeMap::extract_ifandBTreeSet::extract_if(std 1.91, with a range). #547 landed the hash map's and set's; this finishes the B-tree's, part of the m3 "all of std" plan. No consumer calls them yet.Approach
rt.BTreeExtractIfkeeps std's cursor: the leaf and index of the entry it reads next. A removal that rebalances only merges the leaf with one neighbor or takes from it. So the cursor follows without comparing keys: it moves into the previous leaf if this one merged into it, or shifts by what that leaf gave to this one's front.ExtractIfInner:start_boundonce, only for a map with a root (m.r).end_boundat each key, before the predicate, and compares byPartialOrd::le/lt. A key of the crate's own passes its own tests, asrangepasseseq/gt.size_hintis(0, Some(len))of the live map.&mut Vpredicate gets a place where JS copies the value (place_call), so writes land on kept entries too.DebugwritesExtractIf { peek: .., .. }: the next entry, or a set's key, even past the range's end until it stops there, andNoneonce stopped.Ranged::held.rt.boundsOfnow returns{ startBound, endBound }so each bound can be read on its own. Before, it was one function that read both.collections::btree_extracts(differential): maps and sets of up to 510 keys, every range form, partial reads,Debug({:?}and{:#?}), and maps with no root.le/lt, plus a closure and range that drop with the iterator.RangeBoundsof the crate's own that logs each bound read.tests/btree.tsagainst std (runtime.rs):extract_ifover random ranges of a ~20k-entry tree, read part way, with the tree's shape checked after.le, swapping the drop order, reading the start of a rootless map, and peeking after a stop each fail the differential, and the first also failsbtree.ts.Impact
rt.btreeExtractIf,rt.btreeExtractIfMut,rt.btreeExtractKeysIf,rt.fmtBTreeExtractIf.rt.boundsOfreturns a{ startBound, endBound }record instead of a function (ts/MIGRATE.md). Generated code is unchanged.Alternatives
retaindoes: O(n) pernext, and wrong for a read-part-way iterator unless it rebuilds on drop. Rejected.mem::forget). Rejected.rt.boundsOfa function and call it at every key: that would readstart_boundagain at each key, which std doesn't do.Follow-ups
removeAt, whichpop_first,pop_last,remove, and nowextract_ifshare, still callsOrd::cmpto rebalance where std's removals call none. A B-tree's searches call Ord as std's do now names these removals in its Goal (5ca5a9b).drop_tree), while the runtime drops in key order (stable 1.98.1's order). This was already the maintainer's decision of 2026-10-30, recorded ints/README.md, so the new fixture drains its logged map in order. No new quest.Review
quest review: Codex, gpt-6.1-sol, medium effort. Round 3, head d724cc2: no findings.Ord::cmp, unlike std's. Refuted as the existingremoveAtbehavior (pop_firsthas it too), which the B-tree search-order quest now covers.🤖 Generated with Claude Code