Dictionary lookup errors when the struct contains empty vectors

SInce you didn’t implement 2 arg hash in code that uses it (like Dict) that falls back to the default hash which uses objectref, and so they hash differently

julia> hash(n_1, UInt(0))
0x416534e228463c4d

julia> hash(n_2, UInt(0))
0x65ee65d3463e8fcc

You need to implement 2 argument hash.
(don’t implement 1 argument hash)

e.g.

Base.hash(n::Node, h::UInt) = sum(hash, children(n); init=h) 

(I am a little dubious of using sum in hash and would consider reduce(xor, but that is another discussion)

2 Likes