JuliaCollections / JuliaCollections/FunctionalCollections.jl

PersistentHashMap: `get` with default throws KeyError

Open
#61 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
126
Forks
33
PR merge metrics
No merged PRs in 30d

Description

I've been getting some keyerrors when calling get(m, key, 0) where m::PersistentHashMap.

Based on a cursory look at the FunctionalCollections source code, it looks to me like the issue is arising because when checking whether there is a value for the key so it knows whether to return the default, the method get(::PersistentHashMap, key, default) instead checks whether there is a value for any key with the same hash as key. I don't think I understand the source code fully enough to be sure this is the problem, though.

(I'm referring to the following method, defined at PersistentHashMap.jl:149 on my install:)

function Base.get(m::PersistentHashMap, key, default)
    val = get(m.trie, reinterpret(Int, hash(key)), NotFound())
    (val === NotFound()) && return default
    val[key]
end

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at PersistentHashMap.jl:149 and reproduce Base.get(m, key, default) with a PersistentHashMap and a missing key. Trace how the trie lookup handles hash matches, then add regression coverage showing that a missing key returns the supplied default without throwing KeyError.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.