[][src]Struct intrusive_splay_tree::SplayTree

pub struct SplayTree<'a, T> where
    T: IntrusiveNode<'a>,
    T::Elem: 'a, 
{ /* fields omitted */ }

An intrusive splay tree.

The tree is parameterized by some marker type T whose IntrusiveNode implementation defines:

  • the element type contained in this tree: T::Elem,
  • how to get the intrusive node for this tree within an element,
  • and how to get the container element from a given intrusive node for this tree.

Implementations

impl<'a, T> SplayTree<'a, T> where
    T: 'a + IntrusiveNode<'a>, 
[src]

pub fn is_empty(&self) -> bool[src]

Is this tree empty?

pub fn root(&self) -> Option<&'a T::Elem>[src]

Get a reference to the root element, if any exists.

pub fn find<K: ?Sized>(&mut self, key: &K) -> Option<&'a T::Elem> where
    K: TreeOrd<'a, T>, 
[src]

Find an element in the tree.

This operation will splay the queried element to the root of the tree.

The key must be of a type that implements TreeOrd for this tree's T type. The element type T::Elem must always implement TreeOrd<T>, so you can search the tree by element. You can also implement TreeOrd<T> for additional key types. This allows you to search the tree without constructing a full element.

pub fn insert(&mut self, elem: &'a T::Elem) -> bool[src]

Insert a new element into this tree.

Returns true if the element was inserted into the tree.

Returns false if there was already an element in the tree for which TreeOrd returned Ordering::Equal. In this case, the extant element is left in the tree, and elem is not inserted.

This operation will splay the inserted element to the root of the tree.

It is a logic error to insert an element that is already inserted in a T tree.

Panics

If debug_assertions are enabled, then this function may panic if elem is already in a T tree. If debug_assertions are not defined, the behavior is safe, but unspecified.

pub fn remove<K: ?Sized>(&mut self, key: &K) -> Option<&'a T::Elem> where
    K: TreeOrd<'a, T>, 
[src]

Find and remove an element from the tree.

If a matching element is found and removed, then Some(removed_element) is returned. Otherwise None is returned.

The key must be of a type that implements TreeOrd for this tree's T type. The element type T::Elem must always implement TreeOrd<T>, so you can remove an element directly. You can also implement TreeOrd<T> for additional key types. This allows you to search the tree without constructing a full element, and remove the element that matches the given key, if any.

pub fn walk<F, C>(&self, f: F) -> Option<C::Result> where
    F: FnMut(&'a T::Elem) -> C,
    C: WalkControl
[src]

Walk the tree in order.

The C type controls whether iteration should continue, or break and return a C::Result value. You can use () as C, and that always continues iteration. Using Result<(), E> as C allows you to halt iteration on error, and propagate the error value. Using Option<T> as C allows you to search for some value, halt iteration when its found, and return it.

Trait Implementations

impl<'a, T> Debug for SplayTree<'a, T> where
    T: 'a + IntrusiveNode<'a>,
    T::Elem: 'a + Debug
[src]

impl<'a, T> Default for SplayTree<'a, T> where
    T: 'a + IntrusiveNode<'a>,
    T::Elem: 'a, 
[src]

impl<'a, T> Extend<&'a <T as IntrusiveNode<'a>>::Elem> for SplayTree<'a, T> where
    T: 'a + IntrusiveNode<'a>, 
[src]

impl<'a, T> FromIterator<&'a <T as IntrusiveNode<'a>>::Elem> for SplayTree<'a, T> where
    T: 'a + IntrusiveNode<'a>,
    T::Elem: Debug
[src]

Auto Trait Implementations

impl<'a, T> !Send for SplayTree<'a, T>

impl<'a, T> !Sync for SplayTree<'a, T>

impl<'a, T> Unpin for SplayTree<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.