Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get values as array efficiently #110

Open
aplavin opened this issue Sep 10, 2022 · 2 comments
Open

Get values as array efficiently #110

aplavin opened this issue Sep 10, 2022 · 2 comments

Comments

@aplavin
Copy link
Contributor

aplavin commented Sep 10, 2022

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.

@mtfishman
Copy link
Contributor

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

@andyferris
Copy link
Owner

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

Hmm… what about hijacking vec?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants