Files
swift-collections/Sources
Karoy LorenteyandClaude Sonnet 4.6 2bbcb92987 [SortedCollections] _BTree.lastIndex(forKey:): Fix off-by-one guard and missing slot offset
The guard `slot > 0` incorrectly excluded `slot == 0`, causing the function
to return `endIndex` whenever the matching element was at position 0 of any
node. Changed to `slot >= 0`.

The non-leaf fallback was also missing `offset += slot`, matching the same
bug that exists symmetrically in startIndex(forKey:). The absolute offset
of element[k] in a non-leaf node is ancestors + sum(subtreeCount[0..k]) + k;
the `+k` term was absent.

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