JuliaCollections / DataStructures.jl

Julia implementation of Data structures
https://juliacollections.github.io/DataStructures.jl/latest/
MIT License
692 stars 246 forks source link

Heterogeneous multi dict #222

Open jw3126 opened 8 years ago

jw3126 commented 8 years ago

I can do

Dict(1 => 1, 2=> "two")

but

using DataStructures
MultiDict(1 => 1, 2 => "two")

throws an error:

LoadError: MethodError: no method matching DataStructures.MultiDict{K,V}(::Pair{Int64,Int64}, ::Pair{Int64,String})
Closest candidates are:
  DataStructures.MultiDict{K,V}{K,V}(!Matched::Pair{K,V}...) at /home/jan/.julia/v0.6/DataStructures/src/multi_dict.jl:36
  DataStructures.MultiDict{K,V}(::Any) at /home/jan/.julia/v0.6/DataStructures/src/multi_dict.jl:20
  DataStructures.MultiDict{K,V}{T}(::Any) at sysimg.jl:66
while loading In[27], in expression starting on line 2

is this expected?

kmsquire commented 8 years ago

Certainly not desired. https://github.com/JuliaLang/DataStructures.jl/blob/52615e84024f2ac666469fb8f2af95a6194ad84c/src/multi_dict.jl is almost certainly missing a relevant constructor. Pull requests welcome!

jw3126 commented 8 years ago

Yeah I tried to fix it, but so far I keep hitting https://github.com/JuliaLang/julia/issues/19159.

kmsquire commented 8 years ago

@wildart I originally thought this issue was related to SortedMultiDicts, because I forgot that you had contributed a MultiDict implementation. Since there are no docs for MultiDict, it's hard to know what the expected behavior or solution is here. Would you be able to add some documentation under doc/source/?

bjarthur commented 7 years ago

same problem for SortedDict:

julia> SortedDict(1 => 1, 2 => "two")
ERROR: MethodError: no method matching DataStructures.SortedDict{K,D,Ord<:Base.Order.Ordering}(::Pair{Int64,Int64}, ::Pair{Int64,String})
Closest candidates are:
  DataStructures.SortedDict{K,D,Ord<:Base.Order.Ordering}{K,D}(::Pair{K,D}...) at /Users/arthurb/.julia/v0.5/DataStructures/src/sorted_dict.jl:35
  DataStructures.SortedDict{K,D,Ord<:Base.Order.Ordering}{K,D,Ord<:Base.Order.Ordering}(::Ord<:Base.Order.Ordering, ::Pair{K,D}...) at /Users/arthurb/.julia/v0.5/DataStructures/src/sorted_dict.jl:48
  DataStructures.SortedDict{K,D,Ord<:Base.Order.Ordering}(::Any) at /Users/arthurb/.julia/v0.5/DataStructures/src/sorted_dict.jl:57
  ...
StephenVavasis commented 7 years ago

Yes, it does appear that there is a constructor missing for SortedDict (and also SortedMultiDict). As a temporary workaround, you can try

      SortedDict(Dict(1 => 1, 2 => "two"))