From 1672b2ff7b1c07df797a61a87a48d2313df2fe03 Mon Sep 17 00:00:00 2001 From: "Bowen S. Zhu" Date: Wed, 27 Nov 2024 18:12:31 -0500 Subject: [PATCH] Add docstring in `hash2` about equivalent numbers --- src/types.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/types.jl b/src/types.jl index c48ca14b..2572bd8b 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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}