JuliaCollections / JuliaCollections/DataStructures.jl

Should DefaultDict{K,V} without default value specified have a fallback?

Open
#454 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
745
Forks
261
PR merge metrics
No merged PRs in 30d

Description

Right now we have:

https://github.com/JuliaCollections/DataStructures.jl/blob/31044efe5130b8d1980e2b6650337da08f27274e/src/default_dict.jl#L122

I wonder if we shouldn't fall back to calling the value type with a zero arg constructor.

DefaultDict{K,V}() = DefaultDict{K,V}(V())

This would work well for Vector which is my most common use case for DefaultDicts/

Maybe for numbers we should default to zero, though this is stepping on the grounds of Accumulator

DefaultDict{K,V}() where V<:Number = DefaultDict{K,V}(zero(V))

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

Read src/default_dict.jl around line 122 and review the existing DefaultDict constructors. Resolve whether an unspecified default should call V(), use zero for numeric types, or follow another rule, then define the expected behavior and tests before implementing it.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.