Open cavemanloverboy opened 11 months ago
Clever change! Please bump the version in the Cargo.toml
Will do. Also, it's come to my attention that the drain_filter
method for std::vec::Vec
that this was supposed to be analogous to has been renamed to extract_if
:
https://github.com/rust-lang/rust/issues/43244
I'll try to come up with some better names for the methods.
extract_if
to match the method on std
collections (btreemap, vec, etc, e.g. https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#method.extract_if).filter
method since you can just do extract_if
and collect
into collection of your choice -- instead of locking user into Vec
.One final thing we may want to do is either implement DoubleEndedIterator
or remove the rev
fields from the ExtractIf
type
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.