// *** before: ***
struct PointOld: Hashable {
let x: Int
let y: Int
// the mix was invented by the author, and a weak one turned a Set
// into a list with linear search
var hashValue: Int { return x.hashValue ^ y.hashValue }
}
// *** in version 4.2: ***
struct Point: Hashable {
let x: Int
let y: Int
func hash(into hasher: inout Hasher) {
hasher.combine(x) // the fields are fed to the standard hasher
hasher.combine(y)
}
}
// hashValue is deprecated; the hasher is seeded anew on every run of the
// program, so a hash must not be stored on disk or sent over the network
var hasher = Hasher()
hasher.combine(Point(x: 1, y: 2))
print(hasher.finalize())