@@ -54,11 +54,10 @@ struct TestValueCOWTy {
54
54
var _keyCount = _stdlib_AtomicInt ( 0 )
55
55
var _keySerial = _stdlib_AtomicInt ( 0 )
56
56
57
- // A wrapper class that can help us track allocations and find issues with
58
- // object lifetime.
59
- final class TestKeyTy
60
- : Equatable , Hashable , CustomStringConvertible , ExpressibleByIntegerLiteral
61
- {
57
+ class _BaseKeyTy : CustomStringConvertible {
58
+ final var value : Int
59
+ final var serial : Int
60
+
62
61
class var objectCount : Int {
63
62
get {
64
63
return _keyCount. load ( )
@@ -70,18 +69,8 @@ final class TestKeyTy
70
69
71
70
init ( _ value: Int ) {
72
71
_keyCount. fetchAndAdd ( 1 )
73
- serial = _keySerial. addAndFetch ( 1 )
72
+ self . serial = _keySerial. addAndFetch ( 1 )
74
73
self . value = value
75
- self . _hashValue = value
76
- }
77
-
78
- convenience init ( integerLiteral value: Int ) {
79
- self . init ( value)
80
- }
81
-
82
- convenience init ( value: Int , hashValue: Int ) {
83
- self . init ( value)
84
- self . _hashValue = hashValue
85
74
}
86
75
87
76
deinit {
@@ -94,18 +83,60 @@ final class TestKeyTy
94
83
assert ( serial > 0 , " dead TestKeyTy " )
95
84
return value. description
96
85
}
86
+ }
87
+
88
+ // A wrapper class that can help us track allocations and find issues with
89
+ // object lifetime.
90
+ final class TestKeyTy
91
+ : _BaseKeyTy , Equatable , Hashable , ExpressibleByIntegerLiteral
92
+ {
93
+ override init ( _ value: Int ) {
94
+ super. init ( value)
95
+ }
96
+
97
+ convenience init ( integerLiteral value: Int ) {
98
+ self . init ( value)
99
+ }
100
+
101
+ func hash( into hasher: inout Hasher ) {
102
+ hasher. combine ( value)
103
+ }
97
104
98
105
var hashValue : Int {
99
- return _hashValue
106
+ return value
100
107
}
101
108
102
- var value : Int
103
- var _hashValue : Int
104
- var serial : Int
109
+ static func == ( lhs : TestKeyTy , rhs : TestKeyTy ) -> Bool {
110
+ return lhs . value == rhs . value
111
+ }
105
112
}
106
113
107
- func == ( lhs: TestKeyTy , rhs: TestKeyTy ) -> Bool {
108
- return lhs. value == rhs. value
114
+ // A variant of TestKeyTy with precise control over hashing.
115
+ // This is useful for bucket-level tests.
116
+ final class RawTestKeyTy : _BaseKeyTy , Equatable , Hashable
117
+ {
118
+ var _hash : Int
119
+
120
+ init ( value: Int , hashValue: Int ) {
121
+ self . _hash = hashValue
122
+ super. init ( value)
123
+ }
124
+
125
+ var hashValue : Int {
126
+ return _hash
127
+ }
128
+
129
+ func hash( into hasher: inout Hasher ) {
130
+ hasher. combine ( _hash)
131
+ }
132
+
133
+ func _rawHashValue( seed: Int ) -> Int {
134
+ return _hash
135
+ }
136
+
137
+ static func == ( lhs: RawTestKeyTy , rhs: RawTestKeyTy ) -> Bool {
138
+ return lhs. value == rhs. value
139
+ }
109
140
}
110
141
111
142
var _valueCount = _stdlib_AtomicInt ( 0 )
0 commit comments