Skip to content

Commit b261b9d

Browse files
marcoctararslan
authored andcommitted
Fix haskey for PersistentHashMap (#50)
1 parent 60fdcbf commit b261b9d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/PersistentMap.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ function Base.get(m::PersistentHashMap, key, default)
153153
end
154154

155155
function Base.haskey(m::PersistentHashMap, key)
156-
get(m.trie, reinterpret(Int, hash(key)), NotFound()) != NotFound()
156+
val = get(m.trie, reinterpret(Int, hash(key)), NotFound())
157+
(val != NotFound()) && haskey(val, key)
157158
end
158159

159160
function Base.iterate(m::PersistentHashMap)

test/PersistentMapTest.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ const PHM = PersistentHashMap
150150
@test !haskey(m, 2)
151151
end
152152

153+
@testset "haskey dissoc" begin
154+
m = PHM{Int, String}()
155+
m = assoc(m, 1, "one")
156+
m = dissoc(m, 1)
157+
@test !haskey(m, 1)
158+
end
159+
153160
@testset "map" begin
154161
m = PHM((1, 1), (2, 2), (3, 3))
155162
@test map((kv) -> (kv[1], kv[2]+1), m) == PHM((1, 2), (2, 3), (3, 4))

0 commit comments

Comments
 (0)