From 73f009209e99eaed53a6c81bf72dae83a5397cb4 Mon Sep 17 00:00:00 2001 From: Ahmed Abdulkareem Rezik Date: Thu, 9 Jul 2020 14:33:03 +0200 Subject: [PATCH 1/2] Fixed Hashable Conformance to hash(into:) --- Graph/Graph/Edge.swift | 14 +++++++------- Graph/Graph/Vertex.swift | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Graph/Graph/Edge.swift b/Graph/Graph/Edge.swift index ac5ed6a25..61cb576d1 100644 --- a/Graph/Graph/Edge.swift +++ b/Graph/Graph/Edge.swift @@ -29,13 +29,13 @@ extension Edge: CustomStringConvertible { extension Edge: Hashable { - public var hashValue: Int { - var string = "\(from.description)\(to.description)" - if weight != nil { - string.append("\(weight!)") - } - return string.hashValue - } + public func hash(into hasher: inout Hasher) { + hasher.combine(from) + hasher.combine(to) + if weight != nil { + hasher.combine(weight) + } + } } public func == (lhs: Edge, rhs: Edge) -> Bool { diff --git a/Graph/Graph/Vertex.swift b/Graph/Graph/Vertex.swift index 758a367bb..cdf39ba62 100644 --- a/Graph/Graph/Vertex.swift +++ b/Graph/Graph/Vertex.swift @@ -24,8 +24,10 @@ extension Vertex: CustomStringConvertible { extension Vertex: Hashable { - public var hashValue: Int { - return "\(data)\(index)".hashValue + public func hasher(into hasher: inout Hasher){ + + hasher.combine(data) + hasher.combine(index) } } From 0513f7d1d0432d844357f5b931bfc5e0d1940870 Mon Sep 17 00:00:00 2001 From: Ahmed Abdulkareem Rezik Date: Thu, 9 Jul 2020 14:37:37 +0200 Subject: [PATCH 2/2] Fixed Conformance to Hashable Protocol in Vertex and Edge structs --- Graph/Graph/Edge.swift | 14 ++++++++------ Graph/Graph/Vertex.swift | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Graph/Graph/Edge.swift b/Graph/Graph/Edge.swift index 61cb576d1..1f29e07dd 100644 --- a/Graph/Graph/Edge.swift +++ b/Graph/Graph/Edge.swift @@ -29,13 +29,15 @@ extension Edge: CustomStringConvertible { extension Edge: Hashable { + public func hash(into hasher: inout Hasher) { - hasher.combine(from) - hasher.combine(to) - if weight != nil { - hasher.combine(weight) - } - } + hasher.combine(from) + hasher.combine(to) + if weight != nil { + hasher.combine(weight) + } + } + } public func == (lhs: Edge, rhs: Edge) -> Bool { diff --git a/Graph/Graph/Vertex.swift b/Graph/Graph/Vertex.swift index cdf39ba62..45b2c3088 100644 --- a/Graph/Graph/Vertex.swift +++ b/Graph/Graph/Vertex.swift @@ -24,11 +24,13 @@ extension Vertex: CustomStringConvertible { extension Vertex: Hashable { - public func hasher(into hasher: inout Hasher){ - - hasher.combine(data) - hasher.combine(index) - } + + + public func hasher(into hasher: inout Hasher){ + + hasher.combine(data) + hasher.combine(index) + } }

AltStyle によって変換されたページ (->オリジナル) /