From 04d1591c7dcab4600baa9ecfc6f4123be428b941 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 27 Oct 2017 16:16:43 +0200 Subject: [PATCH] actually cache and use savedhash + tests --- src/AutGroup.jl | 11 +++++++---- test/AutGroup-tests.jl | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index 50bb322..56e6758 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -201,8 +201,11 @@ end hash(s::AutSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(:AutSymbol, h))) function hash(g::AutGroupElem, h::UInt) - gs = gens(parent(g).objectGroup) - return hash(g(gs), hash(typeof(g), hash(parent(g), h))) + if g.modified + g.savedhash = hash(g(gens(parent(g).objectGroup)), hash(typeof(g), hash(parent(g), h))) + g.modified = false + end + return g.savedhash end function change_pow(s::AutSymbol, n::Int) @@ -316,7 +319,7 @@ function reduce!(W::AutGroupElem) end end - W.modified = false - W.savedhash = hash(W.symbols,hash(typeof(W))) + W.modified = true + return W end diff --git a/test/AutGroup-tests.jl b/test/AutGroup-tests.jl index 0436d4d..e7adc3d 100644 --- a/test/AutGroup-tests.jl +++ b/test/AutGroup-tests.jl @@ -149,6 +149,16 @@ b = Groups.flip_autsymbol(2)*A(inv(Groups.rmul_autsymbol(1,2))) @test a*b == b*a @test a^3 * b^3 == A() + g,h = Nemo.gens(A)[[1,8]] + domain = Nemo.gens(A.objectGroup) + @test (g*h)(domain) == (h*g)(domain) + @test (g*h).savedhash != (h*g).savedhash + a = g*h + b = h*g + @test hash(a) == hash(b) + @test a.savedhash == b.savedhash + @test length(unique([a,b])) == 1 + @test length(unique([g*h, h*g])) == 1 end @testset "specific Aut(F4) tests" begin