From 944fad0f02e676eb78ba6a6a80a06ccc014918a0 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 15 Dec 2018 00:47:20 -0600 Subject: [PATCH] Make GridPoint support dictionaries Add hashValue propertiy and Hashable protocol --- Sources/AOC2018/tools.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/AOC2018/tools.swift b/Sources/AOC2018/tools.swift index 87ddc15..1870f23 100644 --- a/Sources/AOC2018/tools.swift +++ b/Sources/AOC2018/tools.swift @@ -19,9 +19,14 @@ func == (tuple1:(T,T),tuple2:(T,T)) -> Bool return (tuple1.0 == tuple2.0) && (tuple1.1 == tuple2.1) } -struct GridPoint: Equatable, Comparable { +struct GridPoint: Equatable, Comparable, Hashable { var X = 0 var Y = 0 + var hashValue: Int { + get { + return X.hashValue ^ Y.hashValue + } + } static func == (lhs: GridPoint, rhs: GridPoint) -> Bool { return (lhs.X == rhs.X) && (lhs.Y == rhs.Y)