Dictionaries.jl
Dictionaries.jl copied to clipboard
Get values as array efficiently
The most intuitive way to get the array of values from an AbstractDictionary is collect(dict). However, it always allocates, even if values are readily available, as in Dictionary.values.
I would like to propose creating a function that returns dict.values if it's present (eg Dictionary), and does collect(dict) otherwise (eg PairDictionary). Not sure what it's name should be, though. It's like collect, but possibly without a copy.
Maybe the semantics could be convert(Vector, dict)? I've also come across situations where I have wanted this functionality (though in many way Dictionary acts like a Vector but with more general indexing so in general it seems like this could be avoided with generic programming).
convert is a bag of worms - dictionaries assume the operation doesn’t affect the lookup of a key.
Hmm… what about hijacking vec?