Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gafter opened this issue Sep 5, 2023 · 0 comments
Open

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

gafter opened this issue Sep 5, 2023 · 0 comments

Comments

@gafter
Copy link
Member

gafter commented Sep 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant