pub struct AvlTree<P, Tag>{ /* private fields */ }Expand description
Implementations§
Source§impl<P, Tag> AvlTree<P, Tag>
impl<P, Tag> AvlTree<P, Tag>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub fn add(&mut self, node: P) -> Result<(), P>
pub fn add(&mut self, node: P) -> Result<(), P>
Adds a new node to the tree, requires P::Target has Ord.
(If you want more freedom of Ordering, see also Self::entry_with)
- Returns
Ok(())if the node was added, takes the ownership of P. - Err(P) if an equivalent node already exists
Sourcepub fn remove_by_key<K>(&mut self, key: &K) -> Option<P>
pub fn remove_by_key<K>(&mut self, key: &K) -> Option<P>
remove a node from the tree (need P::Target to impl Borrow)
Sourcepub fn remove(&mut self, node: &P)
pub fn remove(&mut self, node: &P)
remove a node from the tree (useful if P is multiple ownership)
Sourcepub fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, P, Tag, K>
pub fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, P, Tag, K>
Searches for an element in the tree with key, requires P::Target can borrow to K type,
and have a total ordering by K.
Sourcepub fn entry_with<'a, K, F>(
&'a mut self,
key: K,
cmp_f: F,
) -> Entry<'a, P, Tag, K>
pub fn entry_with<'a, K, F>( &'a mut self, key: K, cmp_f: F, ) -> Entry<'a, P, Tag, K>
Searches for an element in the tree with key and custom compare function.
pub fn get<'a, K>(&'a self, key: &K) -> Option<AvlNodeRef<'a, P>>
pub fn get_with<'a, F>(&'a self, cmp_f: F) -> Option<AvlNodeRef<'a, P>>
Sourcepub fn iter(&self) -> AvlIter<'_, P, Tag> ⓘ
pub fn iter(&self) -> AvlIter<'_, P, Tag> ⓘ
return a iterator to get the reference
NOTE: The iterator yield AvlNodeRef, so that you can clone the reference if it’s Arc
Sourcepub fn iter_rev(&self) -> AvlIter<'_, P, Tag> ⓘ
pub fn iter_rev(&self) -> AvlIter<'_, P, Tag> ⓘ
return a reversed iterator to get the reference.
NOTE: The iterator yield AvlNodeRef, so that you can clone the reference if it’s Arc
Sourcepub fn into_iter_rev(self) -> AvlIntoIter<P, Tag> ⓘ
pub fn into_iter_rev(self) -> AvlIntoIter<P, Tag> ⓘ
Into reversed order iterator that consume the items
pub fn prev<'a>(&'a self, data: &'a P::Target) -> Option<AvlNodeRef<'a, P>>
pub fn next<'a>(&'a self, data: &'a P::Target) -> Option<AvlNodeRef<'a, P>>
pub fn first<'a>(&'a self) -> Option<AvlNodeRef<'a, P>>
pub fn last<'a>(&'a self) -> Option<AvlNodeRef<'a, P>>
Sourcepub fn first_entry<'a>(&'a mut self) -> Entry<'a, P, Tag, First>
pub fn first_entry<'a>(&'a mut self) -> Entry<'a, P, Tag, First>
Get the last entry
You can use Entry::prepend or Entry::prepend_unchecked on it to batch insert
Sourcepub fn last_entry<'a>(&'a mut self) -> Entry<'a, P, Tag, Last>
pub fn last_entry<'a>(&'a mut self) -> Entry<'a, P, Tag, Last>
Get the last entry
You can use Entry::append or Entry::append_unchecked on it to batch insert