File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,47 @@ public func run_Dictionary2(N: Int) {
36
36
}
37
37
CheckResults ( res == ref_result, " Incorrect results in Dictionary2: \( res) != \( ref_result) " )
38
38
}
39
+
40
+ class Box < T : Hashable where T : Equatable > : Hashable {
41
+ var value : T
42
+
43
+ init ( _ v: T ) {
44
+ value = v
45
+ }
46
+
47
+ var hashValue : Int {
48
+ return value. hashValue
49
+ }
50
+ }
51
+
52
+ extension Box : Equatable {
53
+ }
54
+
55
+ func == < T: Equatable > ( lhs: Box < T > , rhs: Box < T > ) -> Bool {
56
+ return lhs. value == rhs. value
57
+ }
58
+
59
+ @inline ( never)
60
+ public func run_Dictionary2OfObjects( N: Int ) {
61
+ let size = 500
62
+ let ref_result = 199
63
+ var res = 0
64
+ for _ in 1 ... 5 * N {
65
+ var x : [ Box < String > : Box < Int > ] = [ : ]
66
+ for i in 1 ... size {
67
+ x [ Box ( String ( i, radix: 16 ) ) ] = Box ( i)
68
+ }
69
+
70
+ res = 0
71
+ for i in 0 ..< size {
72
+ let i2 = size- i
73
+ if x [ Box ( String ( i2) ) ] != nil {
74
+ res += 1
75
+ }
76
+ }
77
+ if res != ref_result {
78
+ break
79
+ }
80
+ }
81
+ CheckResults ( res == ref_result, " Incorrect results in Dictionary2AllObjects: \( res) != \( ref_result) " )
82
+ }
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ precommitTests = [
121
121
" Dictionary " : run_Dictionary,
122
122
" DictionaryOfObjects " : run_DictionaryOfObjects,
123
123
" Dictionary2 " : run_Dictionary2,
124
+ " Dictionary2OfObjects " : run_Dictionary2OfObjects,
124
125
" Dictionary3 " : run_Dictionary3,
125
126
" DictionaryBridge " : run_DictionaryBridge,
126
127
" DictionaryLiteral " : run_DictionaryLiteral,
You can’t perform that action at this time.
0 commit comments