Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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