Skip to content

Commit c64a5f2

Browse files
authored
Merge pull request #129 from jpsim/update-hashable
Update `Hashable` conformance
2 parents 64bceaa + 7f9eff9 commit c64a5f2

5 files changed

Lines changed: 47 additions & 0 deletions

File tree

Sources/Yams/Node.Mapping.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ extension Node.Mapping: Equatable {
7373
}
7474
}
7575

76+
#if swift(>=4.1.50)
77+
extension Node.Mapping: Hashable {
78+
/// :nodoc:
79+
public func hash(into hasher: inout Hasher) {
80+
hasher.combine(pairs)
81+
hasher.combine(resolvedTag)
82+
}
83+
}
84+
#endif
85+
7686
extension Node.Mapping: ExpressibleByDictionaryLiteral {
7787
/// :nodoc:
7888
public init(dictionaryLiteral elements: (Node, Node)...) {
@@ -187,9 +197,11 @@ private struct Pair<Value: Comparable & Equatable>: Comparable, Equatable {
187197
self.value = value
188198
}
189199

200+
#if !swift(>=4.1.50)
190201
static func == (lhs: Pair, rhs: Pair) -> Bool {
191202
return lhs.key == rhs.key && lhs.value == rhs.value
192203
}
204+
#endif
193205

194206
static func < (lhs: Pair<Value>, rhs: Pair<Value>) -> Bool {
195207
return lhs.key < rhs.key
@@ -199,3 +211,7 @@ private struct Pair<Value: Comparable & Equatable>: Comparable, Equatable {
199211
return (key: pair.key, value: pair.value)
200212
}
201213
}
214+
215+
#if swift(>=4.1.50)
216+
extension Pair: Hashable where Value: Hashable {}
217+
#endif

Sources/Yams/Node.Scalar.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ extension Node.Scalar: Equatable {
8888
}
8989
}
9090

91+
#if swift(>=4.1.50)
92+
extension Node.Scalar: Hashable {
93+
/// :nodoc:
94+
public func hash(into hasher: inout Hasher) {
95+
hasher.combine(string)
96+
hasher.combine(resolvedTag)
97+
}
98+
}
99+
#endif
100+
91101
extension Node.Scalar: TagResolvable {
92102
static let defaultTagName = Tag.Name.str
93103
func resolveTag(using resolver: Resolver) -> Tag.Name {

Sources/Yams/Node.Sequence.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ extension Node.Sequence: Equatable {
7777
}
7878
}
7979

80+
#if swift(>=4.1.50)
81+
extension Node.Sequence: Hashable {
82+
/// :nodoc:
83+
public func hash(into hasher: inout Hasher) {
84+
hasher.combine(nodes)
85+
hasher.combine(resolvedTag)
86+
}
87+
}
88+
#endif
89+
8090
extension Node.Sequence: ExpressibleByArrayLiteral {
8191
/// :nodoc:
8292
public init(arrayLiteral elements: Node...) {

Sources/Yams/Node.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ extension Node {
186186
// MARK: Hashable
187187

188188
extension Node: Hashable {
189+
#if !swift(>=4.1.50)
189190
/// This `Node`'s Hashable `hashValue`.
190191
public var hashValue: Int {
191192
switch self {
@@ -216,6 +217,7 @@ extension Node: Hashable {
216217
return false
217218
}
218219
}
220+
#endif
219221
}
220222

221223
// MARK: Comparable

Sources/Yams/Tag.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ extension Tag: CustomStringConvertible {
7979
}
8080

8181
extension Tag: Hashable {
82+
#if swift(>=4.1.50)
83+
/// :nodoc:
84+
public func hash(into hasher: inout Hasher) {
85+
hasher.combine(name)
86+
}
87+
#else
8288
/// :nodoc:
8389
public var hashValue: Int {
8490
return name.hashValue
8591
}
92+
#endif
8693

8794
/// :nodoc:
8895
public static func == (lhs: Tag, rhs: Tag) -> Bool {
@@ -98,6 +105,7 @@ extension Tag.Name: ExpressibleByStringLiteral {
98105
}
99106

100107
extension Tag.Name: Hashable {
108+
#if !swift(>=4.1.50)
101109
/// :nodoc:
102110
public var hashValue: Int {
103111
return rawValue.hashValue
@@ -107,6 +115,7 @@ extension Tag.Name: Hashable {
107115
public static func == (lhs: Tag.Name, rhs: Tag.Name) -> Bool {
108116
return lhs.rawValue == rhs.rawValue
109117
}
118+
#endif
110119
}
111120

112121
// http://www.yaml.org/spec/1.2/spec.html#Schema

0 commit comments

Comments
 (0)