Skip to main content

AvlTree

Struct AvlTree 

Source
pub struct AvlTree<P, Tag>
where P: Pointer, P::Target: AvlItem<Tag>,
{ /* private fields */ }
Expand description

An intrusive AVL tree (balanced binary search tree).

Elements in the tree must implement the AvlItem trait. The tree supports various pointer types (Box, Arc, Rc, etc.) through the Pointer trait.

Implementations§

Source§

impl<P, Tag> AvlTree<P, Tag>
where P: Pointer, P::Target: AvlItem<Tag>,

Source

pub fn new() -> Self

Creates a new, empty AvlTree.

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn add(&mut self, node: P) -> Result<(), P>
where P::Target: Ord,

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
Source

pub fn remove_by_key<K>(&mut self, key: &K) -> Option<P>
where P::Target: Borrow<K>, K: Ord,

remove a node from the tree (need P::Target to impl Borrow)

Source

pub fn remove(&mut self, node: &P)
where P::Target: Ord,

remove a node from the tree (useful if P is multiple ownership)

Source

pub fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, P, Tag, K>
where P::Target: Borrow<K>, K: Ord,

Searches for an element in the tree with key, requires P::Target can borrow to K type, and have a total ordering by K.

Source

pub fn entry_with<'a, K, F>( &'a mut self, key: K, cmp_f: F, ) -> Entry<'a, P, Tag, K>
where F: Fn(&K, &P::Target) -> Ordering,

Searches for an element in the tree with key and custom compare function.

Source

pub fn get<'a, K>(&'a self, key: &K) -> Option<AvlNodeRef<'a, P>>
where P::Target: Borrow<K>, K: Ord,

Source

pub fn get_with<'a, F>(&'a self, cmp_f: F) -> Option<AvlNodeRef<'a, P>>
where F: Fn(&P::Target) -> Ordering,

Source

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

Source

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

Source

pub fn into_iter_rev(self) -> AvlIntoIter<P, Tag> ⓘ

Into reversed order iterator that consume the items

Source

pub fn prev<'a>(&'a self, data: &'a P::Target) -> Option<AvlNodeRef<'a, P>>

Source

pub fn next<'a>(&'a self, data: &'a P::Target) -> Option<AvlNodeRef<'a, P>>

Source

pub fn first<'a>(&'a self) -> Option<AvlNodeRef<'a, P>>

Source

pub fn last<'a>(&'a self) -> Option<AvlNodeRef<'a, P>>

Source

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

Source

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

Source

pub fn dump<F>(&self, print_cb: F)
where F: Fn(&P::Target, usize),

Source

pub fn validate(&self)
where P::Target: Ord,

Trait Implementations§

Source§

impl<P, Tag> Debug for AvlTree<P, Tag>
where P: Pointer, P::Target: AvlItem<Tag> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P, Tag> Default for AvlTree<P, Tag>
where P: Pointer + Send, P::Target: AvlItem<Tag>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<P, Tag> Drop for AvlTree<P, Tag>
where P: Pointer, P::Target: AvlItem<Tag>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'a, P, Tag> IntoIterator for &'a AvlTree<P, Tag>
where P: Pointer, P::Target: AvlItem<Tag>,

Source§

type Item = AvlNodeRef<'a, P>

The type of the elements being iterated over.
Source§

type IntoIter = AvlIter<'a, P, Tag>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<P, Tag> IntoIterator for AvlTree<P, Tag>
where P: Pointer, P::Target: AvlItem<Tag>,

Source§

type Item = P

The type of the elements being iterated over.
Source§

type IntoIter = AvlIntoIter<P, Tag>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<P, Tag> Send for AvlTree<P, Tag>
where P: Pointer + Send, P::Target: AvlItem<Tag>,

Source§

impl<P, Tag> Sync for AvlTree<P, Tag>
where P: Pointer + Send, P::Target: AvlItem<Tag>,

Auto Trait Implementations§

§

impl<P, Tag> Freeze for AvlTree<P, Tag>

§

impl<P, Tag> RefUnwindSafe for AvlTree<P, Tag>

§

impl<P, Tag> Unpin for AvlTree<P, Tag>
where <P as Pointer>::Target: Sized, *mut <P as Pointer>::Target: Unpin, PhantomData<fn(P, &Tag)>: Unpin,

§

impl<P, Tag> UnsafeUnpin for AvlTree<P, Tag>

§

impl<P, Tag> UnwindSafe for AvlTree<P, Tag>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.