Skip to content

Commit 8e77a26

Browse files
committed
[test] StdlibUnittest: Add missing hash(into:) implementations
1 parent 792a50e commit 8e77a26

File tree

5 files changed

+22
-40
lines changed

5 files changed

+22
-40
lines changed

stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ public struct _CollectionState : Equatable, Hashable {
305305
}
306306
}
307307

308-
public var hashValue: Int {
309-
return _id.hashValue
308+
public func hash(into hasher: inout Hasher) {
309+
hasher.combine(_id)
310310
}
311311
}
312312

stdlib/private/StdlibUnicodeUnittest/Collation.swift

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -181,42 +181,11 @@ let ducetExtractData: [CollationTableEntry] = [
181181
CollationTableEntry([0xE01EF], [0x0000_0000_0000], "VARIATION SELECTOR-256"),
182182
]
183183

184-
public struct HashableArray<Element : Hashable> : Hashable {
185-
internal var _elements: [Element]
186-
187-
public init(_ elements: [Element]) {
188-
_elements = elements
189-
}
190-
191-
public var hashValue: Int {
192-
// FIXME: this is a bad approach to combining hash values.
193-
var result = 0
194-
for x in _elements {
195-
result ^= x.hashValue
196-
result = result &* 997
197-
}
198-
return result
199-
}
200-
}
201-
202-
public func == <Element>(
203-
lhs: HashableArray<Element>,
204-
rhs: HashableArray<Element>
205-
) -> Bool {
206-
return lhs._elements.elementsEqual(rhs._elements)
207-
}
208-
209-
extension HashableArray : ExpressibleByArrayLiteral {
210-
public init(arrayLiteral elements: Element...) {
211-
self._elements = elements
212-
}
213-
}
214-
215-
let ducetExtract: [HashableArray<Unicode.Scalar> : CollationTableEntry] = {
184+
let ducetExtract: [[Unicode.Scalar]: CollationTableEntry] = {
216185
() in
217-
var result: [HashableArray<Unicode.Scalar> : CollationTableEntry] = [:]
186+
var result: [[Unicode.Scalar]: CollationTableEntry] = [:]
218187
for entry in ducetExtractData {
219-
result[HashableArray(entry.scalars)] = entry
188+
result[entry.scalars] = entry
220189
}
221190
return result
222191
}()
@@ -232,7 +201,7 @@ extension String {
232201
internal var _collationElements: [UInt64] {
233202
var result: [UInt64] = []
234203
for us in self.unicodeScalars {
235-
let scalars: HashableArray<Unicode.Scalar> = [us]
204+
let scalars: [Unicode.Scalar] = [us]
236205
let collationElements = ducetExtract[scalars]!.collationElements
237206
if collationElements[0] != 0 {
238207
result += collationElements

stdlib/private/StdlibUnittest/LifetimeTracked.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ extension LifetimeTracked : Hashable {
5151
public var hashValue: Int {
5252
return value
5353
}
54+
public func hash(into hasher: inout Hasher) {
55+
hasher.combine(value)
56+
}
5457
}
5558

5659
extension LifetimeTracked : Strideable {

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,20 @@ public func <=> <T: Comparable>(lhs: T, rhs: T) -> ExpectedComparisonResult {
110110
}
111111

112112
public struct TypeIdentifier : Hashable, Comparable {
113+
public var value: Any.Type
114+
113115
public init(_ value: Any.Type) {
114116
self.value = value
115117
}
116118

117119
public var hashValue: Int { return objectID.hashValue }
118-
public var value: Any.Type
119-
120-
internal var objectID : ObjectIdentifier { return ObjectIdentifier(value) }
120+
public func hash(into hasher: inout Hasher) {
121+
hasher.combine(objectID)
122+
}
123+
124+
internal var objectID : ObjectIdentifier {
125+
return ObjectIdentifier(value)
126+
}
121127
}
122128

123129
public func < (lhs: TypeIdentifier, rhs: TypeIdentifier) -> Bool {

stdlib/private/StdlibUnittest/StringConvertible.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public struct CustomPrintableValue
6565
return value.hashValue
6666
}
6767

68+
public func hash(into hasher: inout Hasher) {
69+
hasher.combine(value)
70+
}
71+
6872
public typealias Stride = Int
6973

7074
public func distance(to other: CustomPrintableValue) -> Stride {

0 commit comments

Comments
 (0)