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

rename _hashing_data to equality_data

This commit is contained in:
Marek Kaluba 2021-05-16 22:27:54 +02:00
parent 472e78af27
commit 6405a1868e
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 12 additions and 14 deletions

View File

@ -33,7 +33,7 @@ function relations(G::AutomorphismGroup)
return last(gersten_relations(n, commutative=false)) return last(gersten_relations(n, commutative=false))
end 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} function Base.:(==)(g::A, h::A) where A<:FPGroupElement{<:AutomorphismGroup}
@assert parent(g) === parent(h) @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 img_computed, imh_computed = false, false
if !_isvalidhash(g) if !_isvalidhash(g)
img = _hashing_data(g) img = equality_data(g)
_update_savedhash!(g, img) _update_savedhash!(g, img)
img_computed = true img_computed = true
end end
if !_isvalidhash(h) if !_isvalidhash(h)
imh = _hashing_data(h) imh = equality_data(h)
_update_savedhash!(h, imh) _update_savedhash!(h, imh)
imh_computed = true imh_computed = true
end end
@ -68,17 +68,15 @@ function Base.:(==)(g::A, h::A) where A<:FPGroupElement{<:AutomorphismGroup}
hash(g) != hash(h) && return false hash(g) != hash(h) && return false
# words are different, but hashes agree # words are different, but hashes agree
if !img_computed @sync begin
img = _hashing_data(g) !img_computed && Threads.@spawn img = equality_data(g)
end !imh_computed && Threads.@spawn imh = equality_data(h)
if !imh_computed
imh = _hashing_data(h)
end end
res = img == imh equal = img == imh
!res && @warn "hash collision in == :" g h equal || @warn "hash collision in == :" g h
return res return equal
end end
# eye-candy # eye-candy

View File

@ -1,6 +1,6 @@
## Hashing ## 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) bitget(h::UInt, n::Int) = Bool((h & (1 << n)) >> n)
bitclear(h::UInt, n::Int) = h & ~(1 << 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 # To update hash use this internal method, possibly only after computing the
# normal form of `g`: # 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 = hash(data, hash(parent(g)))
h = (h << count_ones(__BITFLAGS_MASK)) | (__BITFLAGS_MASK & g.savedhash) h = (h << count_ones(__BITFLAGS_MASK)) | (__BITFLAGS_MASK & g.savedhash)
g.savedhash = _setvalidhash(h, true) g.savedhash = _setvalidhash(h, true)
@ -36,7 +36,7 @@ end
function Base.hash(g::FPGroupElement, h::UInt) function Base.hash(g::FPGroupElement, h::UInt)
normalform!(g) normalform!(g)
_isvalidhash(g) || _update_savedhash!(g) _isvalidhash(g) || _update_savedhash!(g, equality_data(g))
return hash(g.savedhash >> count_ones(__BITFLAGS_MASK) , h) return hash(g.savedhash >> count_ones(__BITFLAGS_MASK) , h)
end end