Dictionaries.jl icon indicating copy to clipboard operation
Dictionaries.jl copied to clipboard

Get values as array efficiently

Open aplavin opened this issue 3 years ago • 2 comments

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.

aplavin avatar Sep 10 '22 09:09 aplavin

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).

mtfishman avatar Nov 22 '22 21:11 mtfishman

convert is a bag of worms - dictionaries assume the operation doesn’t affect the lookup of a key.

Hmm… what about hijacking vec?

andyferris avatar Nov 23 '22 12:11 andyferris