Files
swift-collections/Sources
Karoy LorenteyandClaude Sonnet 4.6 dd44e73a1b [SortedCollections] _BTree.startIndex(forKey:): Fix missing slot offset in non-leaf fallback
When the key was found at slot k of an internal node but an earlier
occurrence was sought in the child subtree and not found, the fallback
path returned the internal-node element's position.  The absolute offset
formula for element[k] in a non-leaf node is:

  ancestors + sum(subtreeCount[0..k]) + k

The `+ k` (slot) term was omitted, so the returned index carried the
wrong offset for any key that lives at slot > 0 of an internal node.

Add test_startIndexForKey (BTree Tests) to verify the offset for every
key in trees of several sizes, and test_rangeSubscript (SortedSet Tests)
to exercise the SortedSet[range] subscript which depends on this method.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 15:58:40 -07:00
..
2026-04-30 13:35:01 -07:00