8000 Fixed Hashable Conformance to hash(into:) · mcFactor/swift-algorithm-club@73f0092 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73f0092

Browse files
committed
Fixed Hashable Conformance to hash(into:)
1 parent 667d265 commit 73f0092

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Graph/Graph/Edge.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ extension Edge: CustomStringConvertible {
2929

3030
extension Edge: Hashable {
3131

32-
public var hashValue: Int {
33-
var string = "\(from.description)\(to.description)"
34-
if weight != nil {
35-
string.append("\(weight!)")
36-
}
37-
return string.hashValue
38-
}
32+
public func hash(into hasher: inout Hasher) {
33+
hasher.combine(from)
34+
hasher.combine(to)
35+
if weight != nil {
36+
hasher.combine(weight)
37+
}
38+
}
3939
}
4040

4141
public func == <T>(lhs: Edge<T>, rhs: Edge<T>) -> Bool {

Graph/Graph/Vertex.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ extension Vertex: CustomStringConvertible {
2424

2525
extension Vertex: Hashable {
2626

27-
public var hashValue: Int {
28-
return "\(data)\(index)".hashValue
27+
public func hasher(into hasher: inout Hasher){
28+
29+
hasher.combine(data)
30+
hasher.combine(index)
2931
}
3032

3133
}

0 commit comments

Comments
 (0)
0