-
Notifications
You must be signed in to change notification settings - Fork 17
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
add filter functionality #16
base: master
Are you sure you want to change the base?
Conversation
const MAX_SIZE: usize, | ||
> Drop for RedBlackTreeDrainFilter<'a, K, V, P, MAX_SIZE> | ||
{ | ||
fn drop(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gist of the speed up here is that the traversal traversal to remove nodes is O(K) instead of O(K log N) right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually still O(K log N) but you save a log N on the find
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, with remove
you have to traverse the tree from the root to the entry to re-find the node addr of the entry you just found.
If you iterate through the elements and record the addr instead of the keys, you don't have to do that traversal to remove the entry. That's the gist
src/red_black_tree.rs
Outdated
.nodes | ||
.get((ptr - 1) as usize) | ||
.unwrap() | ||
.get_value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there not a helper function to perform this lookup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was mostly copied from the iterator implementation, but perhaps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched to get_node
. much neater
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever change! Please bump the version in the Cargo.toml
Will do. Also, it's come to my attention that the I'll try to come up with some better names for the methods. |
|
One final thing we may want to do is either implement |
This provides a
drain_filter
andfilter
functionality on the red black tree implementation.Inspiration: in
phoenix-v1
'sCancelAllOrders
instruction, the tree is traversed and matching ids are collected. These ids are then used viabook.remove(...)
which traverses the tree to remove the entry. Instead of traversing the tree, this implementation records allocator node addresses and removes them all upon dropping the newRedBlackTreeDrainFilter
type.A quick and dirty benchmark of 128 removals from a full tree of 4096 items yields the following results on an M2 Max:
which is an O(30%) reduction in the wall time of the removals.