Make GridPoint support dictionaries
Add hashValue propertiy and Hashable protocol
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user