on Sun Oct 23 2016, milos wrote:
> Given an array of instances of a `Hashable` value type, all equal
> according to `Equatable` protocol, but with distinct `hashValue`s,
Equal hashables must have the same hashValue. If you violate this rule,
all bets are off. As the doc says:
A hash value
Yes, Rien, just realised that. Now I must find some place to hide in
shame…
Thanks for your reply, though!
milos
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
Ah, one should never post to a mailing list before a morning coffee! The
reason for the essentially undefined behaviour is that `Hashable`
conformance must guarantee that two instances have the same `hashValue`
if they are `==`, **but not vice versa**! In other words, the equality
in the code s
If you change the “==“ function to:
func == (lhs: X, rhs: X) -> Bool {
return (lhs.x == rhs.x) && (lhs.hashValue == rhs.hashValue)
}
then the example works as expected.
Apple says this: “A hash value, provided by a type’s hashValue property, is an
integer that is the same for any two instan
Given an array of instances of a `Hashable` value type, all equal
according to `Equatable` protocol, but with distinct `hashValue`s, I
would expect that initialising a set with that array would preserve all
the instances. Instead, running the code below in an iOS playground on
Xcode 8.0 (8A218a