diff --git a/src/new_autgroups.jl b/src/new_autgroups.jl index 4c628a0..4be666a 100644 --- a/src/new_autgroups.jl +++ b/src/new_autgroups.jl @@ -33,7 +33,7 @@ function relations(G::AutomorphismGroup) return last(gersten_relations(n, commutative=false)) end -_hashing_data(f::FPGroupElement{<:AutomorphismGroup}) = normalform!.(evaluate(f)) +equality_data(f::FPGroupElement{<:AutomorphismGroup}) = normalform!.(evaluate(f)) function Base.:(==)(g::A, h::A) where A<:FPGroupElement{<:AutomorphismGroup} @assert parent(g) === parent(h) @@ -52,12 +52,12 @@ function Base.:(==)(g::A, h::A) where A<:FPGroupElement{<:AutomorphismGroup} img_computed, imh_computed = false, false if !_isvalidhash(g) - img = _hashing_data(g) + img = equality_data(g) _update_savedhash!(g, img) img_computed = true end if !_isvalidhash(h) - imh = _hashing_data(h) + imh = equality_data(h) _update_savedhash!(h, imh) imh_computed = true end @@ -68,17 +68,15 @@ function Base.:(==)(g::A, h::A) where A<:FPGroupElement{<:AutomorphismGroup} hash(g) != hash(h) && return false # words are different, but hashes agree - if !img_computed - img = _hashing_data(g) - end - if !imh_computed - imh = _hashing_data(h) + @sync begin + !img_computed && Threads.@spawn img = equality_data(g) + !imh_computed && Threads.@spawn imh = equality_data(h) end - res = img == imh - !res && @warn "hash collision in == :" g h + equal = img == imh + equal || @warn "hash collision in == :" g h - return res + return equal end # eye-candy diff --git a/src/new_hashing.jl b/src/new_hashing.jl index 20dceab..3c771c2 100644 --- a/src/new_hashing.jl +++ b/src/new_hashing.jl @@ -1,6 +1,6 @@ ## Hashing -_hashing_data(g::FPGroupElement) = word(g) +equality_data(g::FPGroupElement) = (normalform!(g); word(g)) bitget(h::UInt, n::Int) = Bool((h & (1 << n)) >> n) bitclear(h::UInt, n::Int) = h & ~(1 << n) @@ -27,7 +27,7 @@ _setvalidhash!(g::FPGroupElement, v::Bool) = # To update hash use this internal method, possibly only after computing the # normal form of `g`: -function _update_savedhash!(g::FPGroupElement, data=_hashing_data(g)) +function _update_savedhash!(g::FPGroupElement, data) h = hash(data, hash(parent(g))) h = (h << count_ones(__BITFLAGS_MASK)) | (__BITFLAGS_MASK & g.savedhash) g.savedhash = _setvalidhash(h, true) @@ -36,7 +36,7 @@ end function Base.hash(g::FPGroupElement, h::UInt) normalform!(g) - _isvalidhash(g) || _update_savedhash!(g) + _isvalidhash(g) || _update_savedhash!(g, equality_data(g)) return hash(g.savedhash >> count_ones(__BITFLAGS_MASK) , h) end