Skip to content

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

@gafter

Description

@gafter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions