JuliaCollections / JuliaCollections/DataStructures.jl

How to efficiently modify all values of a SortedDict?

Open
#812 2 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

With normal Dict I can

b=Dict(3=>4)
map!(v->v*2, values(b))

b
Dict{Int64, Int64} with 1 entry:
  3 => 8

With SortedDict I can't

a=SortedDict(2=>3)
map!(v->v*2, values(a))

ERROR: MethodError: no method matching map!(::var"#7#8", ::DataStructures.SDMValIteration{SortedDict{Int64, Int64, Base.Order.ForwardOrdering}})
Closest candidates are:
  map!(::Any, ::Base.ValueIterator{<:Dict}) at dict.jl:736
  map!(::Any, ::Base.ValueIterator{<:WeakKeyDict}) at weakkeydict.jl:140
  map!(::Tf, ::SparseArrays.AbstractSparseMatrixCSC, ::Union{LinearAlgebra.Bidiagonal, LinearAlgebra.Diagonal, LinearAlgebra.LowerTriangular, LinearAlgebra.SymTridiagonal, LinearAlgebra.Tridiagonal, LinearAlgebra.UnitLowerTriangular, LinearAlgebra.UnitUpperTriangular, LinearAlgebra.UpperTriangular, SparseArrays.SparseMatrixCSC}, ::Union{LinearAlgebra.Bidiagonal, LinearAlgebra.Diagonal, LinearAlgebra.LowerTriangular, LinearAlgebra.SymTridiagonal, LinearAlgebra.Tridiagonal, LinearAlgebra.UnitLowerTriangular, LinearAlgebra.UnitUpperTriangular, LinearAlgebra.UpperTriangular, SparseArrays.SparseMatrixCSC}...) where {Tf, N} at /opt/julia/julia-1.8.0-beta3/share/julia/stdlib/v1.8/SparseArrays/src/higherorderfns.jl:1162

I can do

for (k,v) in a
       a[k]*=2
       end

but it would be less efficient

thanks

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 by examining SortedDict, its values(a) iterator, and the existing map! behavior for Dict values. Compare how value updates are handled in the supplied loop and determine what support is needed for efficient in-place mapping. Done means the shown map!(v -> v*2, values(a)) example works for SortedDict.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.