Skip to content

Commit

Permalink
Add docstring in hash2 about equivalent numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenszhu committed Nov 27, 2024
1 parent 3f3d013 commit 1672b2f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ objects. Unlike `Base.hash`, which only considers the expression structure, `has
includes the metadata and symtype in the hash calculation. This can be beneficial for hash
consing, allowing for more effective deduplication of symbolically equivalent expressions
with different metadata or symtypes.
Equivalent numbers of different types, such as `0.5::Float64` and
`(1 // 2)::Rational{Int64}`, have the same default `Base.hash` value. The `hash2` function
distinguishes these by including their numeric types in the hash calculation to ensure that
symbolically equivalent expressions with different numeric types are treated as distinct
objects.
"""
hash2(s, salt::UInt) = hash(s, salt)
function hash2(n::T, salt::UInt) where {T <: Number}
Expand Down

0 comments on commit 1672b2f

Please sign in to comment.