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

Include type parameters in hash? #13

Closed
omus opened this issue Jul 25, 2018 · 5 comments
Closed

Include type parameters in hash? #13

omus opened this issue Jul 25, 2018 · 5 comments

Comments

@omus
Copy link

omus commented Jul 25, 2018

For some types the parametric types (or values) should be included in the hash. Probably @auto_hash_equals should use the typeof a type when producing a hash?

@omus
Copy link
Author

omus commented Jul 25, 2018

For an example see: invenia/Intervals.jl#47

@omus omus closed this as completed Jul 25, 2018
@omus omus reopened this Jul 25, 2018
@omus
Copy link
Author

omus commented Jul 25, 2018

(That "close and comment" button is too close to "comment")

goretkin added a commit to goretkin/AutoHashEquals.jl that referenced this issue Jul 30, 2021
type parameters should be a part of the hash
goretkin added a commit to goretkin/AutoHashEquals.jl that referenced this issue Jul 30, 2021
hash the whole type, including type parameters.
All tests pass now.
@matthias314
Copy link

I think that there is a problem with including type parameters into the hash: It violates the requirement that elements with different hashes must not be considered equal. For example, if you define

@auto_hash_equals struct A{T} x::T end

then isequal(A(0), A(0.0)) is true. Hence the hashes have to agree.

@omus
Copy link
Author

omus commented Jan 4, 2022

isequal(A(0), A(0.0)) is true. Hence the hashes have to agree.

A very good point. I cases where additional information is encoded within the type parameters and those types should not hash to be the same (like in the linked example) declaring a hash method seems like a reasonable approach.

Probably the only thing to be done as part of this issue is to document that @auto_hash_equals isn't a good fit for those scenarios.

@gafter
Copy link
Member

gafter commented Aug 18, 2023

This package was completely overhauled in #32. The caller can now decide if type arguments should be considered or not. I made "not" the default for compatibility with existing clients.

Please submit a new issue or PR if you think there is more work to do.

@gafter gafter closed this as completed Aug 18, 2023
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

3 participants