Fast hash for custom type

The 64-bit constant comes from you.

julia> s64 = 0x8aa710fd8cb95e7e
0x8aa710fd8cb95e7e

julia> s32 = UInt32(s64 >> 32) ⊻ UInt32(s64 & 0x00000000ffffffff)
0x061e4e83  # Palli corrected this (see next in thread)

They can be whatever you prefer, although they should not be known to clash with another type’s similar constants.

h += lens_seed is faster than h = hash(lens_seed, h) and all you want to do before calling the inner hash(x.indicies, h) is to morph the incoming h in some way that is consistent for IndexLens. I copied the += approach from Base/hashing.jl, for hashing a String and from Base/tuples.jl hashing.

2 Likes