Struct trees::Forest
[−]
[src]
pub struct Forest<T> { /* fields omitted */ }
Collection of circularly-linked Tree
s
Methods
impl<T> Forest<T>
[src]
pub fn new() -> Forest<T>
[src]
Makes an empty Forest
pub fn push_front(&mut self, tree: Tree<T>)
[src]
add the child as the first child
Examples
use trees::tr; let mut forest = tr(1)-tr(2); forest.push_front( tr(3) ); let mut iter = forest.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(3) ); assert_eq!( iter.next().unwrap().to_owned(), tr(1) ); assert_eq!( iter.next().unwrap().to_owned(), tr(2) ); assert_eq!( iter.next(), None );
pub fn prepend(self, node: Tree<T>) -> Self
[src]
Add the child as the first child and return the Forest
itself
.
pub fn pop_front(&mut self) -> Option<Tree<T>>
[src]
Removes and returns the tree at the front of the forest.
Examples
use trees::{tr,fr}; let mut forest = tr(0)-tr(1)-tr(2); let tree = forest.pop_front(); assert_eq!( tree.unwrap(), tr(0) ); assert_eq!( forest, tr(1)-tr(2) );
pub fn push_back(&mut self, child: Tree<T>)
[src]
Appends the given tree at the end of this forest
Examples
use trees::tr; let mut forest = tr(1)-tr(2); forest.push_back( tr(3) ); let mut iter = forest.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(1) ); assert_eq!( iter.next().unwrap().to_owned(), tr(2) ); assert_eq!( iter.next().unwrap().to_owned(), tr(3) ); assert_eq!( iter.next(), None );
pub fn append(self, child: Tree<T>) -> Self
[src]
Appends the given tree at the end of this forest and return the forest.
pub fn merge(self, other: Self) -> Self
[src]
Merges two forests into one, and return it
Examples
use trees::{tr,fr}; let mut forest = fr().append( tr(1) ).append( tr(2) ); let f2 = fr().append( tr(3) ).append( tr(4) ); forest = forest.merge( f2 ); assert_eq!( forest, tr(1)-tr(2)-tr(3)-tr(4) );
ⓘImportant traits for Iter<'a, T>pub fn children(&self) -> Iter<T>
[src]
Provides a forward iterator over the Forest
's direct decendants
Examples
use trees::tr; let forest = tr(1)/tr(2)/tr(3) - tr(4)/tr(5)/tr(6); let mut iter = forest.children(); //assert_eq!( iter.next().unwrap().clone(), tr(1) /tr(2)/tr(3) ); //assert_eq!( iter.next().unwrap().clone(), tr(4) /tr(5)/tr(6) ); //assert_eq!( iter.next(), None );
ⓘImportant traits for IterMut<'a, T>pub fn children_mut(&mut self) -> IterMut<T>
[src]
Provides a forward iterator over the Forest
's direct decendants with mutable references.
Examples
use trees::tr; let mut forest = ( - ( tr(1) /tr(2)/tr(3) ) - ( tr(4) /tr(5)/tr(6) ) ); for mut tree in forest.children_mut() { tree.data *= 10; } let expected = ( - ( tr(10) /tr(2)/tr(3) ) - ( tr(40) /tr(5)/tr(6) ) ); assert_eq!( forest, expected );
ⓘImportant traits for SubtreeIter<T>pub fn subtrees(&mut self) -> SubtreeIter<T>
[src]
Provides an iterator over the Forest
's subtrees for insert/remove at any position.
Examples
insert after
use trees::tr; let mut forest = tr(1)-tr(2)-tr(3); for mut sub in forest.subtrees() { sub.insert_sib( tr(3) ); } assert_eq!( forest, tr(1)-tr(3)-tr(2)-tr(3)-tr(3)-tr(3) );
insert before
use trees::tr; let mut forest = tr(1)-tr(3)-tr(4); let mut iter = forest.subtrees().peekable(); while let Some(mut sub) = iter.next() { if let Some(next_sub) = iter.peek() { if next_sub.data == 3 { sub.insert_sib( tr(2) ); } } } assert_eq!( forest, tr(1)-tr(2)-tr(3)-tr(4) );
remove
use trees::tr; let mut tree = tr(0) /tr(1)/tr(2)/tr(3)/tr(4)/tr(5)/tr(6); for mut sub in tree.subtrees() { let d = sub.data; if d%2 == 0 || d%3 == 0 { sub.remove(); } } assert_eq!( tree, tr(0) /tr(1)/tr(5) );
pub fn is_empty(&self) -> bool
[src]
Returns true
if the Forest
is empty.
This operation should compute in O(1) time.
Examples
use trees::{tr,fr}; let mut forest = fr(); assert!( forest.is_empty() ); forest.push_back( tr(1) ); assert!( !forest.is_empty() );
Trait Implementations
impl<T> IntoIterator for Forest<T>
[src]
type Item = Tree<T>
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
ⓘImportant traits for IntoIter<T>fn into_iter(self) -> IntoIter<T>
[src]
Consumes the Forest
into an iterator yielding Tree
s.
impl<T> FromIterator<Tree<T>> for Forest<T>
[src]
fn from_iter<I: IntoIterator<Item = Tree<T>>>(iter: I) -> Self
[src]
Creates a value from an iterator. Read more
impl<T> Extend<Tree<T>> for Forest<T>
[src]
fn extend<I: IntoIterator<Item = Tree<T>>>(&mut self, iter: I)
[src]
Extends a collection with the contents of an iterator. Read more
impl<T: Clone> Clone for Forest<T>
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: PartialEq> PartialEq for Forest<T>
[src]
fn eq(&self, other: &Self) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Self) -> bool
[src]
This method tests for !=
.
impl<T: Eq> Eq for Forest<T>
[src]
impl<T: PartialOrd> PartialOrd for Forest<T>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: Ord> Ord for Forest<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<T> Default for Forest<T>
[src]
impl<T> Drop for Forest<T>
[src]
impl<T: Hash> Hash for Forest<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: Debug> Debug for Forest<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Display> Display for Forest<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Send> Send for Forest<T>
[src]
impl<T: Sync> Sync for Forest<T>
[src]
impl<T> Div<Forest<T>> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: Forest<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<&'a Forest<T>> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: &'a Forest<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<Forest<T>> for &'a Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: Forest<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<&'a Forest<T>> for &'a Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: &'a Forest<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<T> Sub<Tree<T>> for Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Tree<T>) -> Self
[src]
Performs the -
operation.
impl<'a, T: Clone> Sub<&'a Tree<T>> for Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: &'a Tree<T>) -> Self
[src]
Performs the -
operation.
impl<'a, T: Clone> Sub<Tree<T>> for &'a Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Tree<T>) -> Forest<T>
[src]
Performs the -
operation.
impl<'a, 'b, T: Clone> Sub<&'b Tree<T>> for &'a Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: &'b Tree<T>) -> Forest<T>
[src]
Performs the -
operation.
impl<T> Sub<Forest<T>> for Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
Performs the -
operation.
impl<'a, T: Clone> Sub<&'a Forest<T>> for Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: &'a Forest<T>) -> Self
[src]
Performs the -
operation.
impl<'a, T: Clone> Sub<Forest<T>> for &'a Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Forest<T>) -> Forest<T>
[src]
Performs the -
operation.