Struct trees::Tree
[−]
[src]
pub struct Tree<T>(_);
Tree with owned Node
s.
Methods
impl<T> Tree<T>
[src]
pub fn new(data: T) -> Tree<T>
[src]
Creates a Tree
with given data on heap.
Tree
is NOT nullable. Consider using an empty Forest
instead if needed.
Examples
use trees::Tree; let tree = Tree::new( 1 ); assert_eq!( tree.data, 1 );
pub fn adopt(self, children: Forest<T>) -> Self
[src]
Append the given trees at the end of the Tree
's children list.
Examples
use trees::tr; let mut tree = tr(0); tree = tree.adopt( -tr(1)-tr(2) ); let mut iter = tree.children(); 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, child: Self) -> Self
[src]
Prepend the given tree at the begin of the Tree
's children list.
Examples
use trees::{tr,fr}; let mut tree = tr(0); tree = tree.prepend( tr(1) ); tree = tree.prepend( tr(2) ); let mut iter = tree.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(2) ); assert_eq!( iter.next().unwrap().to_owned(), tr(1) ); assert_eq!( iter.next(), None );
pub fn append(self, child: Self) -> Self
[src]
Prepend the given tree at the begin of the Tree
's children list.
Examples
use trees::{tr,fr}; let mut tree = tr(0); tree = tree.append( tr(1) ); tree = tree.append( tr(2) ); let mut iter = tree.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(1) ); assert_eq!( iter.next().unwrap().to_owned(), tr(2) ); assert_eq!( iter.next(), None );
Methods from Deref<Target = Node<T>>
pub fn adopt(&mut self, children: Forest<T>)
[src]
Append the given trees at the end of the Node
's children list.
pub fn abandon(&mut self) -> Forest<T>
[src]
Removes and returns the given tree Node
's children.
Examples
use trees::tr; let mut tree = tr(0) /tr(1)/tr(2); let children = tree.abandon(); assert_eq!( tree, tr(0) ); assert_eq!( children, -tr(1)-tr(2) );
pub fn push_front(&mut self, child: Tree<T>)
[src]
Adds the child as the first child.
Examples
use trees::tr; let mut tree = tr(0) /tr(1); tree.push_front( tr(2) ); let mut iter = tree.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(2) ); assert_eq!( iter.next().unwrap().to_owned(), tr(1) ); assert_eq!( iter.next(), None );
pub fn pop_front(&mut self) -> Option<Tree<T>>
[src]
remove and return the first child
Examples
use trees::tr; let mut tree = tr(0) /tr(1)/tr(2); let child = tree.pop_front(); assert_eq!( tree, tr(0) /tr(2) ); assert_eq!( child.unwrap(), tr(1) );
pub fn push_back(&mut self, child: Tree<T>)
[src]
add the child as the last child
Examples
use trees::tr; let mut tree = tr(0) /tr(1); tree.push_back( tr(2) ); let mut iter = tree.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(1) ); assert_eq!( iter.next().unwrap().to_owned(), tr(2) ); assert_eq!( iter.next(), None );
ⓘImportant traits for Iter<'a, T>pub fn children(&self) -> Iter<T>
[src]
Provides a forward iterator over tree Node
's direct decendants
Examples
use trees::tr; let tree = tr(0) /( tr(1) /tr(2)/tr(3) ) /( tr(4) /tr(5)/tr(6) ) ; let mut iter = tree.children(); assert_eq!( iter.next().unwrap().to_owned(), tr(1) /tr(2)/tr(3) ); assert_eq!( iter.next().unwrap().to_owned(), 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 tree Node
's direct decendants with mutable references.
Examples
use trees::tr; let mut tree = tr(0) /( tr(1) /tr(2)/tr(3) ) /( tr(4) /tr(5)/tr(6) ) ; for mut child in tree.children_mut() { child.data *= 10; } let expedted = tr(0) /( tr(10) /tr(2)/tr(3) ) /( tr(40) /tr(5)/tr(6) ) ; assert_eq!( tree, expedted );
ⓘImportant traits for SubtreeIter<T>pub fn subtrees(&mut self) -> SubtreeIter<T>
[src]
Provide an iterator over the tree Node
's subtrees for insert/remove at any position
Examples
insert after
use trees::tr; let mut tree = tr(0) /tr(1)/tr(2)/tr(3); for mut sub in tree.subtrees() { sub.insert_sib( tr(3) ); } assert_eq!( tree, tr(0) /tr(1)/tr(3)/tr(2)/tr(3)/tr(3)/tr(3) );
insert before
use trees::tr; let mut tree = tr(0) /tr(1)/tr(3)/tr(4); let mut iter = tree.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!( tree, tr(0) /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_leaf(&self) -> bool
[src]
Returns true
if the Node
has no children.
This operation should compute in O(1) time.
Examples
use trees::{tr}; let mut tree = tr(0); assert!( tree.is_leaf() ); tree.push_back( tr(1) ); assert!( !tree.is_leaf() );
Trait Implementations
impl<T: PartialEq> PartialEq for Tree<T>
[src]
fn eq(&self, __arg_0: &Tree<T>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Tree<T>) -> bool
[src]
This method tests for !=
.
impl<T: Eq> Eq for Tree<T>
[src]
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 Node<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> 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> Borrow<Node<T>> for Tree<T>
[src]
impl<T> BorrowMut<Node<T>> for Tree<T>
[src]
fn borrow_mut(&mut self) -> &mut Node<T>
[src]
Mutably borrows from an owned value. Read more
impl<T: Clone> Clone for Tree<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> Deref for Tree<T>
[src]
type Target = Node<T>
The resulting type after dereferencing.
fn deref(&self) -> &Node<T>
[src]
Dereferences the value.
impl<T> DerefMut for Tree<T>
[src]
impl<T: Debug> Debug for Tree<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T> Neg for Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn neg(self) -> Forest<T>
[src]
Performs the unary -
operation.
impl<'a, T: Clone> Neg for &'a Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn neg(self) -> Forest<T>
[src]
Performs the unary -
operation.
impl<T> Sub<Self> for Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Forest<T>
[src]
Performs the -
operation.
impl<'a, T: Clone> Sub<&'a Tree<T>> for Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: &'a Tree<T>) -> Forest<T>
[src]
Performs the -
operation.
impl<'a, T: Clone> Sub<Tree<T>> for &'a Tree<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, T: Clone> Sub<Self> for &'a Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Forest<T>
[src]
Performs the -
operation.
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> Div<Tree<T>> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: Tree<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<&'a Tree<T>> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: &'a Tree<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<Tree<T>> for &'a Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: Tree<T>) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<Self> for &'a Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Tree<T>
[src]
Performs the /
operation.
impl<T> Div<()> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, _rhs: ()) -> Tree<T>
[src]
Performs the /
operation.
impl<'a, T: Clone> Div<()> for &'a Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, _rhs: ()) -> 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.