Make GridPoint support dictionaries

Add hashValue propertiy and Hashable protocol
master
Peter 7 years ago
parent 3e711561fa
commit 944fad0f02

@ -19,9 +19,14 @@ func == <T:Equatable> (tuple1:(T,T),tuple2:(T,T)) -> Bool
return (tuple1.0 == tuple2.0) && (tuple1.1 == tuple2.1) return (tuple1.0 == tuple2.0) && (tuple1.1 == tuple2.1)
} }
struct GridPoint: Equatable, Comparable { struct GridPoint: Equatable, Comparable, Hashable {
var X = 0 var X = 0
var Y = 0 var Y = 0
var hashValue: Int {
get {
return X.hashValue ^ Y.hashValue
}
}
static func == (lhs: GridPoint, rhs: GridPoint) -> Bool { static func == (lhs: GridPoint, rhs: GridPoint) -> Bool {
return (lhs.X == rhs.X) && (lhs.Y == rhs.Y) return (lhs.X == rhs.X) && (lhs.Y == rhs.Y)

Loading…
Cancel
Save