1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 18:15:29 +01:00

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) 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 function hash_internal(g::Automorphism, images = freereduce!.(evaluate(g)),
return hash(images, hash(parent(g), hash(Automorphism{N}, h))) h::UInt = HASHINGCONST)
return hash(images, hash(parent(g), h))
end end
function hash(g::Automorphism, h::UInt) function compute_images(g::Automorphism)
if g.modified images = reduce!.(evaluate(g))
g_im = reduce!.(evaluate(g)) g.savedhash = hash_internal(g, images)
g.savedhash = hash(g, g_im) unsetmodified!(g)
g.modified = false return images
end
return xor(g.savedhash, h)
end end
function (==)(g::Automorphism{N}, h::Automorphism{N}) where N 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) change_pow(s::FPSymbol, n::Int) = FPSymbol(s.id, n)
length(s::FPSymbol) = abs(s.pow) 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) change_pow(s::FreeSymbol, n::Int) = FreeSymbol(s.id, n)
length(s::FreeSymbol) = abs(s.pow) 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) 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) return xor(W.savedhash, h)
end end