Skip to content

Commit 84a0596

Browse files
committed
Add docstring for hash2
1 parent 765293a commit 84a0596

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/types.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ function Base.hash(s::BasicSymbolic, salt::UInt)::UInt
332332
end
333333
end
334334

335+
"""
336+
$(TYPEDSIGNATURES)
337+
338+
Calculates a hash value for a `BasicSymbolic` object, incorporating both its metadata and
339+
symtype.
340+
341+
This function provides an alternative hashing strategy to `Base.hash` for `BasicSymbolic`
342+
objects. Unlike `Base.hash`, which only considers the expression structure, `hash2` also
343+
includes the metadata and symtype in the hash calculation. This can be beneficial for hash
344+
consing, allowing for more effective deduplication of symbolically equivalent expressions
345+
with different metadata or symtypes.
346+
"""
335347
hash2(s::BasicSymbolic) = hash2(s, zero(UInt))
336348
function hash2(s::BasicSymbolic{T}, salt::UInt)::UInt where {T}
337349
hash(metadata(s), hash(T, hash(s, salt)))

0 commit comments

Comments
 (0)