Skip to content

Commit c18e485

Browse files
authored
reset maxprobe on empty! (#51595)
As pointed out in #51594 (comment), this is necessary for the assertion added in #49447 to be valid. Fix #51594
1 parent 25f510a commit c18e485

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

base/dict.jl

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ end
184184
resize!(h.keys, newsz)
185185
resize!(h.vals, newsz)
186186
h.ndel = 0
187+
h.maxprobe = 0
187188
return h
188189
end
189190

@@ -259,6 +260,7 @@ function empty!(h::Dict{K,V}) where V where K
259260
resize!(h.vals, sz)
260261
h.ndel = 0
261262
h.count = 0
263+
h.maxprobe = 0
262264
h.age += 1
263265
h.idxfloor = sz
264266
return h

test/dict.jl

+21
Original file line numberDiff line numberDiff line change
@@ -1502,3 +1502,24 @@ for T in (Int, Float64, String, Symbol)
15021502
@test_broken Core.Compiler.is_terminates(Base.infer_effects(getindex, (Dict{T,Any}, T)))
15031503
end
15041504
end
1505+
1506+
struct BadHash
1507+
i::Int
1508+
end
1509+
Base.hash(::BadHash, ::UInt)=UInt(1)
1510+
@testset "maxprobe reset #51595" begin
1511+
d = Dict(BadHash(i)=>nothing for i in 1:20)
1512+
empty!(d)
1513+
sizehint!(d, 0)
1514+
@test d.maxprobe < length(d.keys)
1515+
d[BadHash(1)]=nothing
1516+
@test !(BadHash(2) in keys(d))
1517+
d = Dict(BadHash(i)=>nothing for i in 1:20)
1518+
for _ in 1:20
1519+
pop!(d)
1520+
end
1521+
sizehint!(d, 0)
1522+
@test d.maxprobe < length(d.keys)
1523+
d[BadHash(1)]=nothing
1524+
@test !(BadHash(2) in keys(d))
1525+
end

0 commit comments

Comments
 (0)