AutoHashEquals.jl icon indicating copy to clipboard operation
AutoHashEquals.jl copied to clipboard

Make it a non-breaking change to turn the cache on and off.

Open gafter opened this issue 10 months ago • 0 comments

Some people would like to change whether or not they use the cache, but they need the hash function to be stable when they make that change.

One way to do this would be to generate, when not cacheing

hash(x::MyType) = hash(x.field2, hash(x.field2, type_seed(...))
hash(x::MyType, h::UInt) = hash(hash(x), h)

and when cacheing

hash(x::MyType) = x._cached_hash
hash(x::MyType, h::UInt) = hash(hash(x), h)

These could compute the same hash function, whichever way it is defined.

This could be added under control of another option, so as not to break existing clients and so that only people who ask for this pay the price of the additional hash invocation.

We might define

hash(x::MyType, h::UInt) = (h == 0) ? hash(x) : hash(hash(x), h)

but whether that is a perf improvement in practice would need to be measured.

gafter avatar Sep 05 '23 17:09 gafter