Skip to content

Commit 46c3dd4

Browse files
authored
Merge pull request #123 from lgoettgens/lg/hash-invalidations
Avoid some invalidations related to `Base.hash`
2 parents 862a0f1 + bb261e3 commit 46c3dd4

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/siggb/hashtable.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ end
159159

160160
function insert_in_hash_table!(ht::MonomialHashtable{N}, e::Monomial{N}) where {N}
161161
# generate hash
162-
he = Base.hash(e)
162+
he = hash_monomial(e)
163163

164164
# find new elem position in the table
165165
hidx = he
@@ -201,7 +201,7 @@ end
201201

202202
function find_in_hash_table(ht::MonomialHashtable{N}, e::Monomial{N}) where {N}
203203
# generate hash
204-
he = Base.hash(e)
204+
he = hash_monomial(e)
205205

206206
# find new elem position in the table
207207
hidx = he
@@ -278,7 +278,7 @@ function fill_divmask!(ht::MonomialHashtable{N}) where N
278278
@inbounds for vidx in 1:ht.load
279279
m = ht.exponents[vidx]
280280
divm = divmask(m, ht.divmap, ht.ndivbits)
281-
hsh = Base.hash(m)
281+
hsh = hash_monomial(m)
282282
ht.hashdata[vidx] = Hashvalue(hsh, divm)
283283
end
284284

src/siggb/module.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function construct_module_core(sig::Sig{N},
123123
res_mod_mns[i] = rewr_mod_mns[i]
124124
end
125125
else
126-
hsh = Base.hash(mult)
126+
hsh = hash_monomial(mult)
127127
check_enlarge_hashtable!(basis_ht, plength)
128128
insert_multiplied_poly_in_hash_table!(res_mod_mns, hsh, mult,
129129
rewr_mod_mns,

src/siggb/monomials.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,18 @@ function divmask(e::Monomial{N},
134134
res
135135
end
136136

137-
@generated function makehash(::Val{N}, m) where {N}
137+
@generated function makehash(::Val{N}, m, h::UInt) where {N}
138138
rng = MersenneTwister(18121987)
139-
hash = :( $(UInt64(0)) )
139+
hash = :(h)
140140
for i in 1:N
141141
hash = :($hash + $(rand(rng, MonHash))*(m[$i]))
142142
end
143143
return :($hash % MonHash)
144144
end
145145

146-
Base.hash(a::Monomial{N}) where N = makehash(Val(N), a.exps)
146+
hash_monomial(a::Monomial{N}, h::UInt) where N = makehash(Val(N), a.exps, h)
147+
hash_monomial(a::Monomial{N}) where N = hash_monomial(a, zero(UInt))
148+
Base.hash(a::Monomial{N}, h::UInt) where N = UInt(hash_monomial(a, h))
147149

148150
function leading_monomial(basis::Basis,
149151
basis_ht::MonomialHashtable,

src/siggb/symbolic_pp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ function write_to_matrix_row!(matrix::MacaulayMatrix,
385385
sig::Sig,
386386
row_ind=matrix.nrows+1)
387387

388-
hsh = Base.hash(mult)
388+
hsh = hash_monomial(mult)
389389
poly = basis.monomials[basis_idx]
390390
row = similar(basis.monomials[basis_idx])
391391
check_enlarge_hashtable!(symbol_ht, length(basis.monomials[basis_idx]))

0 commit comments

Comments
 (0)