mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
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>