Struct intrusive_splay_tree::SplayTree
[−]
[src]
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.
Methods
impl<'a, T> SplayTree<'a, T> where
T: 'a + IntrusiveNode<'a>,
[src]
T: 'a + IntrusiveNode<'a>,
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]
K: TreeOrd<'a, T>,
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]
K: TreeOrd<'a, T>,
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]
F: FnMut(&'a T::Elem) -> C,
C: WalkControl,
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> Default for SplayTree<'a, T> where
T: 'a + IntrusiveNode<'a>,
T::Elem: 'a,
[src]
T: 'a + IntrusiveNode<'a>,
T::Elem: 'a,
impl<'a, T> Debug for SplayTree<'a, T> where
T: 'a + IntrusiveNode<'a>,
T::Elem: 'a + Debug,
[src]
T: 'a + IntrusiveNode<'a>,
T::Elem: 'a + Debug,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<'a, T> Extend<&'a T::Elem> for SplayTree<'a, T> where
T: 'a + IntrusiveNode<'a>,
[src]
T: 'a + IntrusiveNode<'a>,
fn extend<I: IntoIterator<Item = &'a T::Elem>>(&mut self, iter: I)
[src]
Extends a collection with the contents of an iterator. Read more
impl<'a, T> FromIterator<&'a T::Elem> for SplayTree<'a, T> where
T: 'a + IntrusiveNode<'a>,
T::Elem: Debug,
[src]
T: 'a + IntrusiveNode<'a>,
T::Elem: Debug,
fn from_iter<I: IntoIterator<Item = &'a T::Elem>>(iter: I) -> Self
[src]
Creates a value from an iterator. Read more