beacon-biosignals / StableHashTraits.jl

Compute hashes over any Julia object simply and reproducibly
MIT License
7 stars 1 forks source link

Change default hash? #19

Closed willow-ahrens closed 1 year ago

willow-ahrens commented 1 year ago

Hello! I greatly appreciate this package! would it be possible to change the default hash in a given context? So many datatypes don't have write defined (nor does it really make sense to define it). A better default for me would be UseQualifiedName(UseProperties()), and only using write on isbits types. Similarly, defaulting to write sometimes leads to collisions when two objects have different types but the same binary representation, and I'd like to include the type of the object in the hash by default. Any tips?

palday commented 1 year ago

https://github.com/beacon-biosignals/StableHashTraits.jl#avoiding-type-piracy has some tips for changing the default hash for types in your context. Something like

struct MyContext end
StableHashTraits.hash_method(::Any, ::MyContext) = UseProperties(:ByOrder)
stable_hash(x; context=MyContext())
haberdashPI commented 1 year ago

We're considering making this change for the default context in #22

haberdashPI commented 1 year ago

Closed by #24