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

Hashes of domains should be consistent with equality #145

Closed
daanhb opened this issue Nov 9, 2023 · 3 comments
Closed

Hashes of domains should be consistent with equality #145

daanhb opened this issue Nov 9, 2023 · 3 comments

Comments

@daanhb
Copy link
Member

daanhb commented Nov 9, 2023

The logic of the hash function should be the same as that of isequal, since the intention is that a == b should imply hash(a) == hash(b). I doubt this is the case right now.

An example when using intervals is given in JuliaMath/IntervalSets.jl#167:

julia> unique([2..1, 3..1])
2-element Vector{ClosedInterval{Int64}}:
 2 .. 1
 3 .. 1

julia> 2..1 == 3..1
true

The fact that 2..1 and 3..1 hash to different values results in unique returning two elements rather than one. DomainSets has an elaborate way of checking for equality of domains, but the hash function doesn't, so I bet there are many more examples of this type of error.

@daanhb
Copy link
Member Author

daanhb commented Feb 16, 2024

Bump, and in addition: defining hash for intervals should not be done in DomainSets.

@daanhb
Copy link
Member Author

daanhb commented Feb 20, 2024

I've concluded that this is hard to do. It is harder than deciding on the equality of domains, because you only have a single argument and not a combination of arguments. Since Point(0.5) == 0.5..0.5 their hashes should be the same. But a closed ball with radius zero is also a point, so should have the same hash. A unit ball in 1D is a unit interval. Etcetera.

@daanhb
Copy link
Member Author

daanhb commented Apr 5, 2024

This was completed in 8742d3a, noting that the definition of hash in Base can still be invoked as a fallback, even if a generic implementation is made at the level of Domain.

@daanhb daanhb closed this as completed Apr 5, 2024
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