Skip to content

Commit

Permalink
== docs: strengthen link between hashing and equality
Browse files Browse the repository at this point in the history
ref #55134.
  • Loading branch information
mbauman authored Jul 15, 2024
1 parent d49a3c7 commit a5ed381
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ Use [`isequal`](@ref) or [`===`](@ref) to always get a `Bool` result.
New numeric types should implement this function for two arguments of the new type, and
handle comparison to other types via promotion rules where possible.
[`isequal`](@ref) falls back to `==`, so new methods of `==` will be used by the
[`Dict`](@ref) type to compare keys. If your type will be used as a dictionary key, it
should therefore also implement [`hash`](@ref).
Equality and hashing are intimately related; two values that are considered [`isequal`](@ref) **must**
have the same [`hash`](@ref). If a type customizes the behavior of `==` and/or [`isequal`](@ref),
then [`hash`](@ref) must be similarly implemented. `Set`s, `Dict`s, and many other internal
implementations assume that this invariant holds.
If some type defines `==`, [`isequal`](@ref), and [`isless`](@ref) then it should
also implement [`<`](@ref) to ensure consistency of comparisons.
Expand Down

0 comments on commit a5ed381

Please sign in to comment.