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

Efficiently iterate over range of keys between [min_key, max_key] #201

Open
breckognize opened this issue Jun 11, 2022 · 1 comment
Open

Comments

@breckognize
Copy link

breckognize commented Jun 11, 2022

The std::collections BTreeMap has a range method that allows for efficiently iterating an adjacent subset of elements between [min_key, max_key]. It would be awesome to have equivalent functionality in this crate where we also have the benefits of structural sharing.

A related request is a remove_range method that removes all the keys between [min key, max key]. I'm not sure if that could be implemented more efficiently in batch vs. just iterating a range and removing the keys one-by-one.

In the meantime, the workaround I see is to call split(min_key) and iterate the right hand side of the split until max_key. But this looks to iterate the entire map, which is prohibitively expensive if we're only interested in a small number of keys:
https://docs.rs/im/11.0.1/src/im/ordmap.rs.html#977

@breckognize breckognize changed the title Iterate over range of keys Efficiently iterate over range of keys between [min_key, max_key] Jun 11, 2022
@breckognize
Copy link
Author

Never mind, this is already supported: https://docs.rs/im/latest/im/ordmap/struct.OrdMap.html#method.range

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

1 participant