From 5810eeb4aed0a1e1e1bc1e114a6916c8ec9e109b Mon Sep 17 00:00:00 2001 From: kalmarek Date: Tue, 24 Mar 2020 23:44:03 +0100 Subject: [PATCH] create uniform hash interface using hash_internal --- src/AutGroup.jl | 19 +++++++++---------- src/FPGroups.jl | 2 -- src/FreeGroup.jl | 2 -- src/Groups.jl | 10 +++++++++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index 7695278..09ed682 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -242,19 +242,18 @@ evaluate(f::Automorphism) = f(domain(parent(f))) const HASHINGCONST = 0x7d28276b01874b19 # hash(Automorphism) -hash(s::AutSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(:AutSymbol, h))) +hash(s::AutSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(AutSymbol, h))) -function hash(g::Automorphism{N}, images, h::UInt=HASHINGCONST) where N - return hash(images, hash(parent(g), hash(Automorphism{N}, h))) +function hash_internal(g::Automorphism, images = freereduce!.(evaluate(g)), + h::UInt = HASHINGCONST) + return hash(images, hash(parent(g), h)) end -function hash(g::Automorphism, h::UInt) - if g.modified - g_im = reduce!.(evaluate(g)) - g.savedhash = hash(g, g_im) - g.modified = false - end - return xor(g.savedhash, h) +function compute_images(g::Automorphism) + images = reduce!.(evaluate(g)) + g.savedhash = hash_internal(g, images) + unsetmodified!(g) + return images end function (==)(g::Automorphism{N}, h::Automorphism{N}) where N diff --git a/src/FPGroups.jl b/src/FPGroups.jl index e7aeb84..ef5b036 100644 --- a/src/FPGroups.jl +++ b/src/FPGroups.jl @@ -95,8 +95,6 @@ end # ############################################################################### -hash(s::FPSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(FPSymbol, h))) - change_pow(s::FPSymbol, n::Int) = FPSymbol(s.id, n) length(s::FPSymbol) = abs(s.pow) diff --git a/src/FreeGroup.jl b/src/FreeGroup.jl index 9e3709e..5f77479 100644 --- a/src/FreeGroup.jl +++ b/src/FreeGroup.jl @@ -80,8 +80,6 @@ end # ############################################################################### -hash(s::FreeSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(FreeSymbol, h))) - change_pow(s::FreeSymbol, n::Int) = FreeSymbol(s.id, n) length(s::FreeSymbol) = abs(s.pow) diff --git a/src/Groups.jl b/src/Groups.jl index ee021e8..64d4e25 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -101,8 +101,16 @@ convert(::Type{GroupWord{T}}, s::T) where {T<:GSymbol} = GroupWord{T}(T[s]) # ############################################################################### +function hash_internal(W::GWord) + reduce!(W) + return hash(syllables(W), hash(typeof(W), hash(parent(W)))) +end + function hash(W::GWord, h::UInt) - W.modified && reduce!(W) + if ismodified(W) + W.savedhash = hash_internal(W) + unsetmodified!(W) + end return xor(W.savedhash, h) end