File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Sources/SortedCollections/BTree
Tests/SortedCollectionsTests/SortedSet Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,12 @@ extension _BTree {
344344 offset += keySlot
345345
346346 if keySlot < handle. elementCount && handle [ keyAt: keySlot] == key {
347+ if !handle. isLeaf {
348+ for i in 0 ... keySlot {
349+ offset += handle [ childAt: i] . storage. header. subtreeCount
350+ }
351+ }
352+
347353 return Index (
348354 node: . passUnretained( storage) ,
349355 slot: keySlot,
Original file line number Diff line number Diff line change @@ -80,6 +80,20 @@ class SortedSetTests: CollectionTestCase {
8080 }
8181 }
8282
83+ func test_indexOf( ) {
84+ withEvery ( " count " , in: 0 ..< 40 ) { count in
85+ let set = SortedSet ( 0 ..< count)
86+ withEvery ( " item " , in: 0 ..< count) { item in
87+ expectNotNil ( set. index ( of: item) ) { index in
88+ expectEqual ( set [ index] , item)
89+ let offset = set. distance ( from: set. startIndex, to: index)
90+ expectEqual ( offset, item)
91+ }
92+ }
93+ expectNil ( set. index ( of: count) )
94+ }
95+ }
96+
8397 func test_removeAtIndex( ) {
8498 withEvery ( " count " , in: 0 ..< 40 ) { count in
8599 withEvery ( " index " , in: 0 ..< count) { index in
You can’t perform that action at this time.
0 commit comments