Skip to content

Commit

Permalink
Fix RobinDict get! getting into infinite loop. Closes JuliaCollection…
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaras committed Dec 7, 2022
1 parent f90dd8c commit e5f060e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/robin_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ end

# insert algorithm
function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
sz = length(h.keys)
(h.count > ROBIN_DICT_LOAD_FACTOR * sz) && rehash!(h, sz<<2)

# table full
@assert h.count != length(h.keys)

Expand Down Expand Up @@ -244,8 +247,6 @@ end

function _setindex!(h::RobinDict{K,V}, key::K, v0) where {K, V}
v = convert(V, v0)
sz = length(h.keys)
(h.count > ROBIN_DICT_LOAD_FACTOR * sz) && rehash!(h, sz<<2)
index = rh_insert!(h, key, v)
@assert index > 0
return h
Expand Down
8 changes: 8 additions & 0 deletions test/test_robin_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ end
end == 16

@test d == RobinDict(8=>19, 19=>2, 42=>4)

d = RobinDict()
for i in 1:100
get!(d, i, i)
end
for i in 1:100
@test get(d, i, nothing) == i
end
end

@testset "push!" begin
Expand Down

0 comments on commit e5f060e

Please sign in to comment.