File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -43,3 +43,54 @@ public func run_Dictionary3(N: Int) {
43
43
}
44
44
CheckResults ( res == ref_result, " Incorrect results in Dictionary3: \( res) != \( ref_result) " )
45
45
}
46
+
47
+ class Box < T : Hashable where T : Equatable > : Hashable {
48
+ var value : T
49
+
50
+ init ( _ v: T ) {
51
+ value = v
52
+ }
53
+
54
+ var hashValue : Int {
55
+ return value. hashValue
56
+ }
57
+ }
58
+
59
+ extension Box : Equatable {
60
+ }
61
+
62
+ func == < T: Equatable > ( lhs: Box < T > , rhs: Box < T > ) -> Bool {
63
+ return lhs. value == rhs. value
64
+ }
65
+
66
+ @inline ( never)
67
+ public func run_Dictionary3OfObjects( N: Int ) {
68
+ let size1 = 100
69
+ let reps = 20
70
+ let ref_result = " 1 99 20 1980 "
71
+ var hash1 : [ Box < String > : Box < Int > ] = [ : ]
72
+ var hash2 : [ Box < String > : Box < Int > ] = [ : ]
73
+ var res = " "
74
+
75
+ for _ in 1 ... N {
76
+ hash1 = [ : ]
77
+ for i in 0 ..< size1 {
78
+ hash1 [ Box ( " foo_ " + String( i) ) ] = Box ( i)
79
+ }
80
+
81
+ hash2 = hash1
82
+
83
+ for _ in 1 ..< reps {
84
+ for (k, v) in hash1 {
85
+ hash2 [ k] = Box ( hash2 [ k] !. value + v. value)
86
+ }
87
+ }
88
+
89
+ res = ( String ( hash1 [ Box ( " foo_1 " ) ] !. value) + " " + String( hash1 [ Box ( " foo_99 " ) ] !. value) + " " +
90
+ String( hash2 [ Box ( " foo_1 " ) ] !. value) + " " + String( hash2 [ Box ( " foo_99 " ) ] !. value) )
91
+ if res != ref_result {
92
+ break
93
+ }
94
+ }
95
+ CheckResults ( res == ref_result, " Incorrect results in Dictionary3OfObject: \( res) != \( ref_result) " )
96
+ }
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ precommitTests = [
123
123
" Dictionary2 " : run_Dictionary2,
124
124
" Dictionary2OfObjects " : run_Dictionary2OfObjects,
125
125
" Dictionary3 " : run_Dictionary3,
126
+ " Dictionary3OfObjects " : run_Dictionary3OfObjects,
126
127
" DictionaryBridge " : run_DictionaryBridge,
127
128
" DictionaryLiteral " : run_DictionaryLiteral,
128
129
" DictionaryRemove " : run_DictionaryRemove,
You can’t perform that action at this time.
0 commit comments