File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -1229,15 +1229,23 @@ DictionaryTestSuite.test("COW.Fast.KeysAccessDoesNotReallocate") {
1229
1229
var lastKey : MinimalHashableValue = d2. first!. key
1230
1230
for i in d2. indices { lastKey = d2 [ i] . key }
1231
1231
1232
+ // index(where:) - linear search
1232
1233
MinimalHashableValue . timesEqualEqualWasCalled = 0
1233
- let j = d2. index ( forKey: lastKey) !
1234
- expectEqual ( 1 , MinimalHashableValue . timesEqualEqualWasCalled)
1234
+ let j = d2. index ( where: { ( k, _) in k == lastKey } ) !
1235
+ expectGE ( MinimalHashableValue . timesEqualEqualWasCalled, 8 )
1236
+
1237
+ // index(forKey:) - O(1) bucket + linear search
1238
+ MinimalHashableValue . timesEqualEqualWasCalled = 0
1239
+ let k = d2. index ( forKey: lastKey) !
1240
+ expectLE ( MinimalHashableValue . timesEqualEqualWasCalled, 4 )
1235
1241
1242
+ // keys.index(of:) - O(1) bucket + linear search
1236
1243
MinimalHashableValue . timesEqualEqualWasCalled = 0
1237
- let k = d2. keys. index ( of: lastKey) !
1238
- expectEqual ( 1 , MinimalHashableValue . timesEqualEqualWasCalled)
1244
+ let l = d2. keys. index ( of: lastKey) !
1245
+ expectLE ( MinimalHashableValue . timesEqualEqualWasCalled, 4 )
1239
1246
1240
1247
expectEqual ( j, k)
1248
+ expectEqual ( k, l)
1241
1249
}
1242
1250
}
1243
1251
You can’t perform that action at this time.
0 commit comments