Dictionaries.jl
Dictionaries.jl copied to clipboard
[Suggestion] mirror Array{Type}(undef, size) style
Array:
Array{Type}(undef, size)
Dictionary:
Dictionary{Key,Value}(inds, undef)
what was the reason for flipping the argument order? OffsetArrays are the most obvious case as it fits into both domains.
Excellent question - thanks!
I have constructors of the form Dictionary(keys, values) - I feel this order makes most sense. To support values being a "scalar-like" thing I'm imagining "broadcasting" values into their places. This leaves undef as the uggly duckling, and I opted for self-consistency. (I kinda feel Base got this wrong; it would be easier to not have Varargs constructors on arrays and to reverse the order there too).
But yes, current compatibility with AbstractArray is annoying. To be fair I still haven't sorted through the dictionary construction (and factory) methods yet.
By the way, I'd generally encourange the usage of similar, as in similar(inds, T) where inds is an AbstractIndices.
(By the way - just in case, please use HashDictionary not Dictionary for collections larger than 10, the Dictionary type is a simple array-based implementation with O(N) lookup).