Struct intrusive_collections::rbtree::RBTree
source · pub struct RBTree<A: Adapter>{ /* private fields */ }
Expand description
An intrusive red-black tree.
When this collection is dropped, all elements linked into it will be converted back to owned pointers and dropped.
Note that you are responsible for ensuring that the elements in a RBTree
remain in ascending key order. This property can be violated, either because
the key of an element was modified, or because the
insert_before
/insert_after
methods of CursorMut
were incorrectly used.
If this situation occurs, memory safety will not be violated but the find
,
upper_bound
, lower_bound
and range
may return incorrect results.
Implementations§
source§impl<A: Adapter> RBTree<A>
impl<A: Adapter> RBTree<A>
sourcepub fn cursor_mut(&mut self) -> CursorMut<'_, A>
pub fn cursor_mut(&mut self) -> CursorMut<'_, A>
Returns a null CursorMut
for this tree.
sourcepub fn cursor_owning(self) -> CursorOwning<A>
pub fn cursor_owning(self) -> CursorOwning<A>
Returns a null CursorOwning
for this tree.
sourcepub unsafe fn cursor_from_ptr(
&self,
ptr: *const <A::PointerOps as PointerOps>::Value,
) -> Cursor<'_, A>
pub unsafe fn cursor_from_ptr( &self, ptr: *const <A::PointerOps as PointerOps>::Value, ) -> Cursor<'_, A>
Creates a Cursor
from a pointer to an element.
§Safety
ptr
must be a pointer to an object that is part of this tree.
sourcepub unsafe fn cursor_mut_from_ptr(
&mut self,
ptr: *const <A::PointerOps as PointerOps>::Value,
) -> CursorMut<'_, A>
pub unsafe fn cursor_mut_from_ptr( &mut self, ptr: *const <A::PointerOps as PointerOps>::Value, ) -> CursorMut<'_, A>
Creates a CursorMut
from a pointer to an element.
§Safety
ptr
must be a pointer to an object that is part of this tree.
sourcepub unsafe fn cursor_owning_from_ptr(
self,
ptr: *const <A::PointerOps as PointerOps>::Value,
) -> CursorOwning<A>
pub unsafe fn cursor_owning_from_ptr( self, ptr: *const <A::PointerOps as PointerOps>::Value, ) -> CursorOwning<A>
Creates a CursorOwning
from a pointer to an element.
§Safety
ptr
must be a pointer to an object that is part of this tree.
sourcepub fn front(&self) -> Cursor<'_, A>
pub fn front(&self) -> Cursor<'_, A>
Returns a Cursor
pointing to the first element of the tree. If the
tree is empty then a null cursor is returned.
sourcepub fn front_mut(&mut self) -> CursorMut<'_, A>
pub fn front_mut(&mut self) -> CursorMut<'_, A>
Returns a CursorMut
pointing to the first element of the tree. If the
the tree is empty then a null cursor is returned.
sourcepub fn front_owning(self) -> CursorOwning<A>
pub fn front_owning(self) -> CursorOwning<A>
Returns a CursorOwning
pointing to the first element of the tree. If the
the tree is empty then a null cursor is returned.
sourcepub fn back(&self) -> Cursor<'_, A>
pub fn back(&self) -> Cursor<'_, A>
Returns a Cursor
pointing to the last element of the tree. If the tree
is empty then a null cursor is returned.
sourcepub fn back_mut(&mut self) -> CursorMut<'_, A>
pub fn back_mut(&mut self) -> CursorMut<'_, A>
Returns a CursorMut
pointing to the last element of the tree. If the
tree is empty then a null cursor is returned.
sourcepub fn back_owning(self) -> CursorOwning<A>
pub fn back_owning(self) -> CursorOwning<A>
Returns a CursorOwning
pointing to the last element of the tree. If the
tree is empty then a null cursor is returned.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all elements from the RBTree
.
This will unlink all object currently in the tree, which requires
iterating through all elements in the RBTree
. Each element is
converted back to an owned pointer and then dropped.
sourcepub fn fast_clear(&mut self)
pub fn fast_clear(&mut self)
Empties the RBTree
without unlinking or freeing objects in it.
Since this does not unlink any objects, any attempts to link these
objects into another RBTree
will fail but will not cause any
memory unsafety. To unlink those objects manually, you must call the
force_unlink
function on them.
source§impl<A: for<'a> KeyAdapter<'a>> RBTree<A>
impl<A: for<'a> KeyAdapter<'a>> RBTree<A>
sourcepub fn find<'a, 'b, Q: ?Sized + Ord>(&'a self, key: &Q) -> Cursor<'a, A>
pub fn find<'a, 'b, Q: ?Sized + Ord>(&'a self, key: &Q) -> Cursor<'a, A>
Returns a Cursor
pointing to an element with the given key. If no such
element is found then a null cursor is returned.
If multiple elements with an identical key are found then an arbitrary one is returned.
sourcepub fn find_mut<'a, 'b, Q: ?Sized + Ord>(
&'a mut self,
key: &Q,
) -> CursorMut<'a, A>
pub fn find_mut<'a, 'b, Q: ?Sized + Ord>( &'a mut self, key: &Q, ) -> CursorMut<'a, A>
Returns a CursorMut
pointing to an element with the given key. If no
such element is found then a null cursor is returned.
If multiple elements with an identical key are found then an arbitrary one is returned.
sourcepub fn find_owning<'a, Q: ?Sized + Ord>(self, key: &Q) -> CursorOwning<A>
pub fn find_owning<'a, Q: ?Sized + Ord>(self, key: &Q) -> CursorOwning<A>
such element is found then a null cursor is returned.
If multiple elements with an identical key are found then an arbitrary one is returned.
sourcepub fn lower_bound<'a, 'b, Q: ?Sized + Ord>(
&'a self,
bound: Bound<&Q>,
) -> Cursor<'a, A>
pub fn lower_bound<'a, 'b, Q: ?Sized + Ord>( &'a self, bound: Bound<&Q>, ) -> Cursor<'a, A>
Returns a Cursor
pointing to the lowest element whose key is above
the given bound. If no such element is found then a null cursor is
returned.
sourcepub fn lower_bound_mut<'a, 'b, Q: ?Sized + Ord>(
&'a mut self,
bound: Bound<&Q>,
) -> CursorMut<'a, A>
pub fn lower_bound_mut<'a, 'b, Q: ?Sized + Ord>( &'a mut self, bound: Bound<&Q>, ) -> CursorMut<'a, A>
Returns a CursorMut
pointing to the first element whose key is
above the given bound. If no such element is found then a null
cursor is returned.
sourcepub fn lower_bound_owning<'a, Q: ?Sized + Ord>(
self,
bound: Bound<&Q>,
) -> CursorOwning<A>
pub fn lower_bound_owning<'a, Q: ?Sized + Ord>( self, bound: Bound<&Q>, ) -> CursorOwning<A>
Returns a CursorOwning
pointing to the first element whose key is
above the given bound. If no such element is found then a null
cursor is returned.
sourcepub fn upper_bound<'a, 'b, Q: ?Sized + Ord>(
&'a self,
bound: Bound<&Q>,
) -> Cursor<'a, A>
pub fn upper_bound<'a, 'b, Q: ?Sized + Ord>( &'a self, bound: Bound<&Q>, ) -> Cursor<'a, A>
Returns a Cursor
pointing to the last element whose key is below
the given bound. If no such element is found then a null cursor is
returned.
sourcepub fn upper_bound_mut<'a, 'b, Q: ?Sized + Ord>(
&'a mut self,
bound: Bound<&Q>,
) -> CursorMut<'a, A>
pub fn upper_bound_mut<'a, 'b, Q: ?Sized + Ord>( &'a mut self, bound: Bound<&Q>, ) -> CursorMut<'a, A>
Returns a CursorMut
pointing to the last element whose key is
below the given bound. If no such element is found then a null
cursor is returned.
sourcepub fn upper_bound_owning<'a, Q: ?Sized + Ord>(
self,
bound: Bound<&Q>,
) -> CursorOwning<A>
pub fn upper_bound_owning<'a, Q: ?Sized + Ord>( self, bound: Bound<&Q>, ) -> CursorOwning<A>
Returns a CursorOwning
pointing to the last element whose key is
below the given bound. If no such element is found then a null
cursor is returned.
sourcepub fn insert<'a>(
&'a mut self,
val: <A::PointerOps as PointerOps>::Pointer,
) -> CursorMut<'_, A>
pub fn insert<'a>( &'a mut self, val: <A::PointerOps as PointerOps>::Pointer, ) -> CursorMut<'_, A>
Inserts a new element into the RBTree
.
The new element will be inserted at the correct position in the tree based on its key.
Returns a mutable cursor pointing to the newly added element.
§Panics
Panics if the new element is already linked to a different intrusive collection.
sourcepub fn entry<'a, Q: ?Sized + Ord>(&'a mut self, key: &Q) -> Entry<'a, A>
pub fn entry<'a, Q: ?Sized + Ord>(&'a mut self, key: &Q) -> Entry<'a, A>
Returns an Entry
for the given key which contains a CursorMut
to an
element with the given key or an InsertCursor
which points to a place
in which to insert a new element with the given key.
This is more efficient than calling find
followed by insert
since
the tree does not have to be searched a second time to find a place to
insert the new element.
If multiple elements with an identical key are found then an arbitrary one is returned.
sourcepub fn range<'a, Min: ?Sized + Ord, Max: ?Sized + Ord>(
&'a self,
min: Bound<&Min>,
max: Bound<&Max>,
) -> Iter<'a, A> ⓘ
pub fn range<'a, Min: ?Sized + Ord, Max: ?Sized + Ord>( &'a self, min: Bound<&Min>, max: Bound<&Max>, ) -> Iter<'a, A> ⓘ
Constructs a double-ended iterator over a sub-range of elements in the
tree, starting at min, and ending at max. If min is Unbounded
, then it
will be treated as “negative infinity”, and if max is Unbounded
, then
it will be treated as “positive infinity”. Thus
range(Unbounded, Unbounded)
will yield the whole collection.