Skip to content

Commit 632fcd5

Browse files
authored
Merge pull request #419 from JuliaSymbolics/myb/sort
Stable hash
2 parents 4ed887c + f29b80b commit 632fcd5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/types.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function (::Type{Sym{T}})(name; metadata=NO_METADATA) where {T}
149149
Sym{T, typeof(metadata)}(name, metadata)
150150
end
151151

152-
Base.hash(s::Sym{T}, u::UInt) where {T} = hash(T, hash(s.name, u))
152+
Base.hash(s::Sym, u::UInt) = hash(s.name, u)
153153

154154
function Base.isequal(a::Sym, b::Sym)
155155
symtype(a) !== symtype(b) && return false
@@ -331,11 +331,13 @@ end
331331
## This is much faster than hash of an array of Any
332332
hashvec(xs, z) = foldr(hash, xs, init=z)
333333

334-
function Base.hash(t::Term{T}, salt::UInt) where {T}
334+
function Base.hash(t::Term, salt::UInt)
335335
!iszero(salt) && return hash(hash(t, zero(UInt)), salt)
336336
h = t.hash[]
337337
!iszero(h) && return h
338-
h′ = hashvec(arguments(t), hash(operation(t), hash(T, salt)))
338+
op = operation(t)
339+
oph = op isa Function ? nameof(op) : op
340+
h′ = hashvec(arguments(t), hash(oph, salt))
339341
t.hash[] = h′
340342
return h′
341343
end

0 commit comments

Comments
 (0)