File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -41,3 +41,50 @@ public func run_DictionaryRemove(N: Int) {
41
41
CheckResults ( tmpDict. isEmpty,
42
42
" tmpDict should be empty: \( tmpDict. count) != 0. " )
43
43
}
44
+
45
+ class Box < T : Hashable where T : Equatable > : Hashable {
46
+ var value : T
47
+
48
+ init ( _ v: T ) {
49
+ value = v
50
+ }
51
+
52
+ var hashValue : Int {
53
+ return value. hashValue
54
+ }
55
+ }
56
+
57
+ extension Box : Equatable {
58
+ }
59
+
60
+ func == < T: Equatable > ( lhs: Box < T > , rhs: Box < T > ) -> Bool {
61
+ return lhs. value == rhs. value
62
+ }
63
+
64
+ @inline ( never)
65
+ public func run_DictionaryRemoveOfObjects( N: Int ) {
66
+ let size = 100
67
+ var dict = Dictionary < Box < Int > , Box < Int > > ( minimumCapacity: size)
68
+
69
+ // Fill dictionary
70
+ for i in 1 ... size {
71
+ dict [ Box ( i) ] = Box ( i)
72
+ }
73
+ CheckResults ( dict. count == size,
74
+ " Incorrect dict count: \( dict. count) != \( size) . " )
75
+
76
+ var tmpDict = dict
77
+ for _ in 1 ... 1000 * N {
78
+ tmpDict = dict
79
+ // Empty dictionary
80
+ for i in 1 ... size {
81
+ tmpDict. removeValue ( forKey: Box ( i) )
82
+ }
83
+ if !tmpDict. isEmpty {
84
+ break
85
+ }
86
+ }
87
+
88
+ CheckResults ( tmpDict. isEmpty,
89
+ " tmpDict should be empty: \( tmpDict. count) != 0. " )
90
+ }
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ precommitTests = [
127
127
" DictionaryBridge " : run_DictionaryBridge,
128
128
" DictionaryLiteral " : run_DictionaryLiteral,
129
129
" DictionaryRemove " : run_DictionaryRemove,
130
+ " DictionaryRemoveOfObjects " : run_DictionaryRemoveOfObjects,
130
131
" DictionarySwap " : run_DictionarySwap,
131
132
" ErrorHandling " : run_ErrorHandling,
132
133
" GlobalClass " : run_GlobalClass,
You can’t perform that action at this time.
0 commit comments