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)))
|
hash(s::AutSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(:AutSymbol, h)))
|
||||||
|
|
||||||
function hash(g::Automorphism, h::UInt)
|
function hash(g::Automorphism, h::UInt)
|
||||||
if g.modified
|
if g.modified
|
||||||
g.savedhash = hash(g(domain(parent(g))), hash(typeof(g), hash(parent(g), h)))
|
g.savedhash = hash(reduce!.(g(domain(parent(g)))),
|
||||||
g.modified = false
|
hash(typeof(g), hash(parent(g), HASHINGCONST)))
|
||||||
end
|
g.modified = false
|
||||||
return g.savedhash
|
end
|
||||||
|
return xor(g.savedhash, h)
|
||||||
end
|
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)
|
function change_pow(s::AutSymbol, n::Int)
|
||||||
if n == 0
|
if n == 0
|
||||||
return id_autsymbol()
|
return id_autsymbol()
|
||||||
|
@ -266,19 +300,6 @@ function show(io::IO, G::AutGroup)
|
||||||
print(io, "Generated by $(join(G.gens, ","))")
|
print(io, "Generated by $(join(G.gens, ","))")
|
||||||
end
|
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
|
# Binary operators
|
||||||
|
|
Loading…
Reference in New Issue