Skip to content

Commit 13b642b

Browse files
committed
Rename the isequal2 function to isequal_with_metadata for clarity.
1 parent 55ca2ec commit 13b642b

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/types.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Modifying `Base.isequal` directly breaks numerous tests in `SymbolicUtils.jl` an
287287
downstream packages like `ModelingToolkit.jl`, hence the need for this separate
288288
function.
289289
"""
290-
function isequal2(a::BasicSymbolic, b::BasicSymbolic)::Bool
290+
function isequal_with_metadata(a::BasicSymbolic, b::BasicSymbolic)::Bool
291291
isequal(a, b) && isequal(metadata(a), metadata(b))
292292
end
293293

@@ -362,23 +362,23 @@ Implements hash consing (flyweight design pattern) for `BasicSymbolic` objects.
362362
This function checks if an equivalent `BasicSymbolic` object already exists. It uses a
363363
custom hash function (`hash2`) incorporating metadata and symtypes to search for existing
364364
objects in a `WeakValueDict` (`wvd`). Due to the possibility of hash collisions (where
365-
different objects produce the same hash), a custom equality check (`isequal2`) which
366-
includes metadata comparison, is used to confirm the equivalence of objects with matching
367-
hashes. If an equivalent object is found, the existing object is returned; otherwise, the
368-
input `s` is returned. This reduces memory usage, improves compilation time for runtime
369-
code generation, and supports built-in common subexpression elimination, particularly when
370-
working with symbolic objects with metadata.
365+
different objects produce the same hash), a custom equality check (`isequal_with_metadata`)
366+
which includes metadata comparison, is used to confirm the equivalence of objects with
367+
matching hashes. If an equivalent object is found, the existing object is returned;
368+
otherwise, the input `s` is returned. This reduces memory usage, improves compilation time
369+
for runtime code generation, and supports built-in common subexpression elimination,
370+
particularly when working with symbolic objects with metadata.
371371
372372
Using a `WeakValueDict` ensures that only weak references to `BasicSymbolic` objects are
373373
stored, allowing objects that are no longer strongly referenced to be garbage collected.
374-
Custom functions `hash2` and `isequal2` are used instead of `Base.hash` and `Base.isequal`
375-
to accommodate metadata without disrupting existing tests reliant on the original behavior
376-
of those functions.
374+
Custom functions `hash2` and `isequal_with_metadata` are used instead of `Base.hash` and
375+
`Base.isequal` to accommodate metadata without disrupting existing tests reliant on the
376+
original behavior of those functions.
377377
"""
378378
function BasicSymbolic(s::BasicSymbolic)::BasicSymbolic
379379
h = hash2(s)
380380
t = get!(wvd, h, s)
381-
if t === s || isequal2(t, s)
381+
if t === s || isequal_with_metadata(t, s)
382382
return t
383383
else
384384
return s

test/basics.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SymbolicUtils: Symbolic, Sym, FnType, Term, Add, Mul, Pow, symtype, operation, arguments, issym, isterm, BasicSymbolic, term, isequal2
1+
using SymbolicUtils: Symbolic, Sym, FnType, Term, Add, Mul, Pow, symtype, operation, arguments, issym, isterm, BasicSymbolic, term, isequal_with_metadata
22
using SymbolicUtils
33
using IfElse: ifelse
44
using Setfield
@@ -340,9 +340,9 @@ end
340340
a1 = setmetadata(a, Ctx1, "meta_1")
341341
a2 = setmetadata(a, Ctx1, "meta_1")
342342
a3 = setmetadata(a, Ctx2, "meta_2")
343-
@test !isequal2(a, a1)
344-
@test isequal2(a1, a2)
345-
@test !isequal2(a1, a3)
343+
@test !isequal_with_metadata(a, a1)
344+
@test isequal_with_metadata(a1, a2)
345+
@test !isequal_with_metadata(a1, a3)
346346
end
347347

348348
@testset "subtyping" begin

0 commit comments

Comments
 (0)