Skip to content

Commit 96ee725

Browse files
natecook1000DougGregor
authored andcommitted
[stdlib] Fix test for different hash layouts
(cherry picked from commit 5aed293)
1 parent f064dca commit 96ee725

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

validation-test/stdlib/Dictionary.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,15 +1229,23 @@ DictionaryTestSuite.test("COW.Fast.KeysAccessDoesNotReallocate") {
12291229
var lastKey: MinimalHashableValue = d2.first!.key
12301230
for i in d2.indices { lastKey = d2[i].key }
12311231

1232+
// index(where:) - linear search
12321233
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)
12351241

1242+
// keys.index(of:) - O(1) bucket + linear search
12361243
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)
12391246

12401247
expectEqual(j, k)
1248+
expectEqual(k, l)
12411249
}
12421250
}
12431251

0 commit comments

Comments
 (0)