Why does my hash function return a different value to the built in hash function?

I copied the hash function code from here:

And ran it under J1.7 but I get different results. Why?

Your second line - that should be:

hash2(x::Any) = hash2(x, zero(UInt))

?

Ok, let me rephrase that
I get the same

julia> hash2((1,2))
0xc04cd80fdd457cea

Still no clue why I don’t get that then:

hash2(x::Any) = hash2(x, zero(UInt))
hash2(@nospecialize(x), h::UInt) = Base.hash_uint(3h - objectid(x))
hash((1,2))==hash2((1,2))

Ah i saw you edited your post - OK good I’m not going crazy.
Anyone shed some light on this?

There’s a special hash function for tuples:

julia> @which hash((1,2), zero(UInt))
hash(t::Tuple, h::UInt64) in Base at tuple.jl:417
5 Likes

I even took hashing.jl, replaced all the hash( with hash2( and got the same result

@which
Everytime I post here I learn of a new helpful macro. Thanks!

1 Like