Skip to content

Commit 468234c

Browse files
mrufsvoldMicah Rufsvold
authored andcommitted
fix: check key values, not get return for haskey(k, orderedrobindict) (#858)
* fix: check key values, not `get` return for haskey(k, orderedrobindict) * Fix: use isequal in setindex! * re-fix: use `get` for `in keys()` but descend to the actual id-dict * Remove accidental paste in docstring * consolidate tests for issue under testset --------- Co-authored-by: Micah Rufsvold <[email protected]>
1 parent d0dd2a0 commit 468234c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/ordered_robin_dict.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
131131
else
132132
@assert haskey(h, key0)
133133
@inbounds orig_v = h.vals[index]
134-
(orig_v != v0) && (@inbounds h.vals[index] = v0)
134+
!isequal(orig_v, v0) && (@inbounds h.vals[index] = v0)
135135
end
136136

137137
check_for_rehash(h) && rehash!(h)
@@ -302,8 +302,8 @@ julia> haskey(D, 'c')
302302
false
303303
```
304304
"""
305-
Base.haskey(h::OrderedRobinDict, key) = (get(h.dict, key, -2) > 0)
306-
Base.in(key, v::Base.KeySet{K,T}) where {K,T<:OrderedRobinDict{K}} = (get(v.dict, key, -1) >= 0)
305+
Base.haskey(h::OrderedRobinDict, key) = (get(h.dict, key, -1) > 0)
306+
Base.in(key, v::Base.KeySet{K,T}) where {K,T<:OrderedRobinDict{K}} = (get(v.dict.dict, key, -1) >= 0)
307307

308308
"""
309309
getkey(collection, key, default)

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import DataStructures: IntSet
77

88
@test [] == detect_ambiguities(Base, Core, DataStructures)
99

10-
tests = ["deprecations",
10+
tests = [
11+
"deprecations",
1112
"int_set",
1213
"sparse_int_set",
1314
"deque",

test/test_ordered_robin_dict.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@
7878
@test od60[14] == 15
7979
end
8080

81+
@testset "Fixes issue 857" begin
82+
h = OrderedRobinDict{Any,Any}([("a", missing), ("b", -2)])
83+
@test 5 == (h["a"] = 5)
84+
@test "b" in keys(h)
85+
@test haskey(h,"b")
86+
end
87+
8188

8289
# #############################
8390
# Copied and modified from Base/test/dict.jl

0 commit comments

Comments
 (0)