From 99d5bc2f8c8b1430fa0b51dc8d1a20634c4a3884 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 25 Mar 2020 03:28:45 +0100 Subject: [PATCH] fast equality for Automorphisms --- src/AutGroup.jl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index accbd26..d58c2b6 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -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 ###############################################################################