mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-11-19 06:30:29 +01:00
New version of hash and ==
evaluation of Automorphism on the standard basis is expensive in hash(g::Automorphism, h::UInt) we 1. compute and store savedhash (evaluating f, if necessary) with a fixed value HASHINGCONST 2. xor h with savedhash in == we evaluate f only at hash-colision (or when This way we evaluate f multiple times only in ~2% of cases (for SAut(F_4))
This commit is contained in:
parent
6a7bb03d73
commit
7139322d05
@ -218,20 +218,54 @@ end
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Basic manipulation
|
||||
# Comparison
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
const HASHINGCONST = 0x314a5215305f3ec1 # more or less random
|
||||
|
||||
hash(s::AutSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(:AutSymbol, h)))
|
||||
|
||||
function hash(g::Automorphism, h::UInt)
|
||||
if g.modified
|
||||
g.savedhash = hash(g(domain(parent(g))), hash(typeof(g), hash(parent(g), h)))
|
||||
g.modified = false
|
||||
end
|
||||
return g.savedhash
|
||||
if g.modified
|
||||
g.savedhash = hash(reduce!.(g(domain(parent(g)))),
|
||||
hash(typeof(g), hash(parent(g), HASHINGCONST)))
|
||||
g.modified = false
|
||||
end
|
||||
return xor(g.savedhash, h)
|
||||
end
|
||||
|
||||
(==)(s::AutSymbol, t::AutSymbol) = s.str == t.str && s.pow == t.pow
|
||||
|
||||
function (==)(g::Automorphism{N}, h::Automorphism{N}) where N
|
||||
parent(g) == parent(h) || return false
|
||||
|
||||
if !g.modified && !h.modified
|
||||
if g.savedhash != h.savedhash
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# expensive:
|
||||
g_im = reduce!.(g(domain(parent(g))))
|
||||
h_im = reduce!.(h(domain(parent(h))))
|
||||
# cheap:
|
||||
g.savedhash = hash(g_im,
|
||||
hash(typeof(g), hash(parent(g), HASHINGCONST)))
|
||||
g.modified = false
|
||||
h.savedhash = hash(h_im,
|
||||
hash(typeof(h), hash(parent(h), HASHINGCONST)))
|
||||
h.modified = false
|
||||
|
||||
return g_im == h_im
|
||||
end
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Basic manipulation
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function change_pow(s::AutSymbol, n::Int)
|
||||
if n == 0
|
||||
return id_autsymbol()
|
||||
@ -266,19 +300,6 @@ function show(io::IO, G::AutGroup)
|
||||
print(io, "Generated by $(join(G.gens, ","))")
|
||||
end
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Comparison
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
(==)(s::AutSymbol, t::AutSymbol) = s.str == t.str && s.pow == t.pow
|
||||
|
||||
function (==)(g::Automorphism, h::Automorphism)
|
||||
parent(g) == parent(h) || return false
|
||||
return g(domain(parent(g))) == h(domain(parent(h)))
|
||||
end
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Binary operators
|
||||
|
Loading…
Reference in New Issue
Block a user