create uniform hash interface using hash_internal

This commit is contained in:
kalmarek 2020-03-24 23:44:03 +01:00
parent 920bc1f28d
commit 5810eeb4ae
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
4 changed files with 18 additions and 15 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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