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

hash definition is not correct #167

Open
hyrodium opened this issue Nov 9, 2023 · 2 comments
Open

hash definition is not correct #167

hyrodium opened this issue Nov 9, 2023 · 2 comments

Comments

@hyrodium
Copy link
Collaborator

hyrodium commented Nov 9, 2023

x-ref: #28 (comment)

julia> using IntervalSets

julia> hash(1..2)
0x3932a21170706f90

julia> hash(OpenInterval(1,2))  # should be different
0x3932a21170706f90

julia> isequal(2..1, 3..1)
true

julia> unique([2..1, 3..1])  # should be 1-element
2-element Vector{ClosedInterval{Int64}}:
 2 .. 1
 3 .. 1
@daanhb
Copy link
Contributor

daanhb commented Nov 9, 2023

Good catch. There is a different definition of hash in DomainSets (which we should remove I suppose) which takes into account openness and so is correct for the first example, but it still gets the second one wrong.

@daanhb
Copy link
Contributor

daanhb commented Feb 16, 2024

How about:

hash(I::TypedEndpointsInterval, h::UInt) =
    isempty(I) ? hash(_interval_hash, h) : hash(isleftopen(I), hash(isrightopen(I), hash(leftendpoint(I), hash(rightendpoint(I), hash(_interval_hash, h)))))

It seems a unique variable _interval_hash is already defined, so for empty intervals we can return that one. For other intervals the openness of the endpoints is included, compared to the current implementation.

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

2 participants