Skip to content

Commit

Permalink
reset maxprobe on empty! (#51595)
Browse files Browse the repository at this point in the history
As pointed out in
#51594 (comment),
this is necessary for the assertion added in
#49447 to be valid.

Fix #51594
  • Loading branch information
oscardssmith authored Oct 5, 2023
1 parent 25f510a commit c18e485
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ end
resize!(h.keys, newsz)
resize!(h.vals, newsz)
h.ndel = 0
h.maxprobe = 0
return h
end

Expand Down Expand Up @@ -259,6 +260,7 @@ function empty!(h::Dict{K,V}) where V where K
resize!(h.vals, sz)
h.ndel = 0
h.count = 0
h.maxprobe = 0
h.age += 1
h.idxfloor = sz
return h
Expand Down
21 changes: 21 additions & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1502,3 +1502,24 @@ for T in (Int, Float64, String, Symbol)
@test_broken Core.Compiler.is_terminates(Base.infer_effects(getindex, (Dict{T,Any}, T)))
end
end

struct BadHash
i::Int
end
Base.hash(::BadHash, ::UInt)=UInt(1)
@testset "maxprobe reset #51595" begin
d = Dict(BadHash(i)=>nothing for i in 1:20)
empty!(d)
sizehint!(d, 0)
@test d.maxprobe < length(d.keys)
d[BadHash(1)]=nothing
@test !(BadHash(2) in keys(d))
d = Dict(BadHash(i)=>nothing for i in 1:20)
for _ in 1:20
pop!(d)
end
sizehint!(d, 0)
@test d.maxprobe < length(d.keys)
d[BadHash(1)]=nothing
@test !(BadHash(2) in keys(d))
end

0 comments on commit c18e485

Please sign in to comment.