1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-19 14:35:28 +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))
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

View File

@ -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