Skip to content

Commit e62f469

Browse files
mrufsvoldMicah Rufsvold
and
Micah Rufsvold
authored
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 d79c5d5 commit e62f469

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/ordered_robin_dict.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
132132
else
133133
@assert haskey(h, key0)
134134
@inbounds orig_v = h.vals[index]
135-
(orig_v != v0) && (@inbounds h.vals[index] = v0)
135+
!isequal(orig_v, v0) && (@inbounds h.vals[index] = v0)
136136
end
137137

138138
check_for_rehash(h) && rehash!(h)
@@ -305,8 +305,8 @@ julia> haskey(D, 'c')
305305
false
306306
```
307307
"""
308-
Base.haskey(h::OrderedRobinDict, key) = (get(h.dict, key, -2) > 0)
309-
Base.in(key, v::Base.KeySet{K,T}) where {K,T<:OrderedRobinDict{K}} = (get(v.dict, key, -1) >= 0)
308+
Base.haskey(h::OrderedRobinDict, key) = (get(h.dict, key, -1) > 0)
309+
Base.in(key, v::Base.KeySet{K,T}) where {K,T<:OrderedRobinDict{K}} = (get(v.dict.dict, key, -1) >= 0)
310310

311311
"""
312312
getkey(collection, key, default)

test/runtests.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import DataStructures: IntSet
88
@test [] == detect_ambiguities(Core, DataStructures)
99
@test [] == detect_ambiguities(Base, DataStructures)
1010

11-
tests = ["deprecations",
11+
tests = [
12+
"deprecations",
1213
"int_set",
1314
"sparse_int_set",
1415
"deque",

test/test_ordered_robin_dict.jl

+7
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)