1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-07-12 01:35:30 +02:00

newnew version of hash and ==

This commit is contained in:
kalmarek 2018-03-29 19:24:15 +02:00
parent d83af99fbc
commit d1db939a63

View File

@ -94,11 +94,7 @@ convert(::Type{GroupWord{T}}, s::T) where {T<:GSymbol} = GroupWord{T}(T[s])
############################################################################### ###############################################################################
function hash(W::GWord, h::UInt) function hash(W::GWord, h::UInt)
if W.modified W.modified && reduce!(W)
reduce!(W)
W.savedhash = hash(W.symbols, hash(typeof(W), hash(parent(W), zero(UInt))))
W.modified = false
end
return xor(W.savedhash, h) return xor(W.savedhash, h)
end end
@ -148,8 +144,9 @@ function reduce!(W::GWord)
reduced = free_reduce!(W) reduced = free_reduce!(W)
end end
end end
deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols))
W.modified = true W.savedhash = hash(W.symbols, hash(typeof(W), hash(parent(W), zero(UInt))))
W.modified = false
return W return W
end end
@ -210,8 +207,8 @@ end
function (==)(W::GWord, Z::GWord) function (==)(W::GWord, Z::GWord)
parent(W) == parent(Z) || return false parent(W) == parent(Z) || return false
W.modified && hash(W) W.modified && reduce!(W)
Z.modified && hash(Z) Z.modified && reduce!(Z)
if W.savedhash != Z.savedhash if W.savedhash != Z.savedhash
return false return false