fast equality for Automorphisms

This commit is contained in:
kalmarek 2020-03-25 03:28:45 +01:00
parent 8248039d63
commit 99d5bc2f8c
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
1 changed files with 19 additions and 14 deletions

View File

@ -249,24 +249,29 @@ function compute_images(g::Automorphism)
end
function (==)(g::Automorphism{N}, h::Automorphism{N}) where N
parent(g) == parent(h) || return false
img_c, imh_c = false, false
if !g.modified && !h.modified
if g.savedhash != h.savedhash
return false
end
if ismodified(g)
img = compute_images(g)
img_c = true
end
# expensive:
g_im = reduce!.(evaluate(g))
h_im = reduce!.(evaluate(h))
# cheap:
g.savedhash = hash(g, g_im)
g.modified = false
h.savedhash = hash(h, h_im)
h.modified = false
if ismodified(h)
imh = compute_images(h)
imh_c = true
end
return g_im == h_im
@assert !ismodified(g) && !ismodified(h)
# cheap
hash(g) != hash(h) && return false # hashes differ, so images must have differed as well
# equal elements, or possibly hash conflict
if !img_c
img = compute_images(g)
end
if !imh_c
imh = compute_images(h)
end
return img == imh
end
###############################################################################