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

Documented check for uniqueness in Set collection #57489

Open
TenzinCHW opened this issue Feb 21, 2025 · 1 comment
Open

Documented check for uniqueness in Set collection #57489

TenzinCHW opened this issue Feb 21, 2025 · 1 comment
Labels
collections Data structures holding multiple items, e.g. sets docs This change adds or pertains to documentation

Comments

@TenzinCHW
Copy link

The documented check for whether an element is in a set is Base.isequal. However, based on the code it seems that a Dict is used as the underlying datastructure, which implies that the check is actually using Base.hash instead.

struct A
    content::Vector{UInt8}
end

Base.hash(a::A) = hash(a.content)
# vs
# Base.isequal(a::A, b::A) = all(a.content .== b.content)

s = Set([A([1]) for _ in 1:2])

If instead the content field of A is a String, defining Base.isequal is not necessary.

@KristofferC
Copy link
Member

You need isequal to deal with hash collisions.

@vtjnash vtjnash added the docs This change adds or pertains to documentation label Feb 21, 2025
@nsajko nsajko added the collections Data structures holding multiple items, e.g. sets label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

4 participants