On Thursday, July 16, 2015 at 9:25:01 AM UTC-7, Matt Bauman wrote:
>
> On Thursday, July 16, 2015 at 12:19:25 PM UTC-4, milktrader wrote:
>>
>> Also, back to the OP question, is the correct solution to simply define
>>
>> Base.hash(f::Foo) = f.x
>>
>
> No, I'd define Base.hash(f::Foo) = hash(f.x, 0x64c74221932dea5b), where I
> chose the constant by rand(UInt). This way it won't collide with other
> types. I really need to spend a bit more time with my interfaces chapter
> and add this info there.
>
>
How would you do this (in a performant way) for a type that has two
internal values? That is, I have
immutable Foo{T}
x::T
y::T
end
Obviously, the hash should be based on both values, right? I could do
Base.hash(f::Foo) = hash(hash(f.x, f.y), 0x64c74221932dea5b)
But that calls hash twice. (Is this even necessary with immutables?)