-
Notifications
You must be signed in to change notification settings - Fork 57
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
Implement .range()
for RedBlackTreeMap
/RedBlackTreeSet
#23
Comments
Not currently, but it is something we want to implement. |
.range()
for RedBlackTreeMap
/RedBlackTreeSet
Are you open to pull requests? |
Sure, PRs are welcomed :) |
So I've been looking into how best to implement the range function. Would it be worth it to add a parent reference to each node? That way we can create a range iterator that will be very optimized. For example: suppose a tree of the following. If I range from 3..9 (all inclusive) I start an inorder traversal, arrive at 3 and give back an iterator. Now all I need to do on each
That said, this all requires that we add a parent reference to each node. This would offer big savings in very large trees. |
I don't think you need the a parent field to do this efficiently. Take a look at how the current iterator works: it maintains a stack that will let you go to the parent node. Try to modify the current iterator (and the normal iterator just calls the "range" iterator with the range You need to change rpds/src/map/red_black_tree_map/mod.rs Lines 1135 to 1149 in b713506
to not go left unless left is within the range. |
I've taken a look at this, and it seems there's a choice to be made: if I try to reuse the existing Do you have any thoughts? |
Good point: it will not be a implement Then we can make |
Is it possible to search RedBlackTreeMap like std's BTreeMap range function?
The text was updated successfully, but these errors were encountered: