[−][src]Struct trees::tree::Tree
Composed of a root Node
and a list of its child Node
s.
Implementations
impl<T> Tree<T>
[src]
pub fn new(data: T) -> Tree<T>
[src]
Creates a Tree
containing only root node associated with given data.
pub fn from_tuple<Tuple, Shape>(tuple: Tuple) -> Self where
Tuple: TupleTree<T, Shape>,
[src]
Tuple: TupleTree<T, Shape>,
Constructs tree from tuple notations.
Examples
use trees::{Tree, tr}; let tree = Tree::<i32>::from_tuple(( 0, (1,2), (3,4) )); assert_eq!( tree, tr(0) /(tr(1)/tr(2)) /(tr(3)/tr(4)) ); assert_eq!( tree.to_string(), "0( 1( 2 ) 3( 4 ) )" );
pub fn root(&self) -> &Node<T>
[src]
Reference of the root node.
pub fn root_mut(&mut self) -> Pin<&mut Node<T>>ⓘ
[src]
Mutable reference of the root node.
pub fn iter_mut<'a, 's: 'a>(&'s mut self) -> IterMut<'a, T>ⓘ
[src]
Provides a forward iterator over child Node
s with mutable references.
Examples
use trees::Tree; let mut tree = Tree::<i32>::from_tuple(( 0, 1, 2, 3 )); tree.iter_mut().for_each( |mut child| *child.data_mut() *= 10 ); assert_eq!( tree.to_string(), "0( 10 20 30 )" );
pub fn push_front(&mut self, tree: Tree<T>)
[src]
Adds the tree as the first child.
Examples
use trees::Tree; let mut tree = Tree::new(0); tree.push_front( Tree::new(1) ); assert_eq!( tree.to_string(), "0( 1 )" ); tree.push_front( Tree::new(2) ); assert_eq!( tree.to_string(), "0( 2 1 )" );
pub fn push_back(&mut self, tree: Tree<T>)
[src]
Adds the tree as the last child.
Examples
use trees::Tree; let mut tree = Tree::new(0); tree.push_back( Tree::new(1) ); assert_eq!( tree.to_string(), "0( 1 )" ); tree.push_back( Tree::new(2) ); assert_eq!( tree.to_string(), "0( 1 2 )" );
pub fn prepend(&mut self, forest: Forest<T>)
[src]
Adds all the forest's trees at front of children list.
Examples
use trees::{Forest, Tree}; let mut tree = Tree::new(0); tree.push_back( Tree::new(1) ); tree.push_back( Tree::new(2) ); let mut forest = Forest::new(); forest.push_back( Tree::new(3) ); forest.push_back( Tree::new(4) ); tree.prepend( forest ); assert_eq!( tree.to_string(), "0( 3 4 1 2 )" );
pub fn append(&mut self, forest: Forest<T>)
[src]
Adds all the forest's trees at back of children list.
Examples
use trees::{Forest, Tree}; let mut tree = Tree::new(0); tree.push_back( Tree::new(1) ); tree.push_back( Tree::new(2) ); let mut forest = Forest::new(); forest.push_back( Tree::new(3) ); forest.push_back( Tree::new(4) ); tree.root_mut().append( forest ); assert_eq!( tree.to_string(), "0( 1 2 3 4 )" );
pub fn abandon(&mut self) -> Forest<T>
[src]
Removes and returns the given Tree
's children.
Examples
use trees::{Forest, Tree}; let mut tree = Tree::new(0); tree.push_back( Tree::new(1) ); tree.push_back( Tree::new(2) ); let forest = tree.abandon(); assert_eq!( forest.to_string(), "( 1 2 )" ); assert_eq!( tree, Tree::new(0) );
pub fn pop_front(&mut self) -> Option<Tree<T>>
[src]
Removes and returns the first child.
Examples
use trees::Tree; let mut tree = Tree::new(0); tree.push_back( Tree::new(1) ); tree.push_back( Tree::new(2) ); assert_eq!( tree.to_string(), "0( 1 2 )" ); assert_eq!( tree.pop_front(), Some( Tree::new(1) )); assert_eq!( tree.to_string(), "0( 2 )" ); assert_eq!( tree.pop_front(), Some( Tree::new(2) )); assert_eq!( tree.to_string(), "0" ); assert_eq!( tree.pop_front(), None );
pub fn pop_back(&mut self) -> Option<Tree<T>>
[src]
Removes and returns the last child.
Examples
use trees::Tree; let mut tree = Tree::new(0); tree.push_back( Tree::new(1) ); tree.push_back( Tree::new(2) ); assert_eq!( tree.to_string(), "0( 1 2 )" ); assert_eq!( tree.pop_back(), Some( Tree::new(2) )); assert_eq!( tree.to_string(), "0( 1 )" ); assert_eq!( tree.pop_back(), Some( Tree::new(1) )); assert_eq!( tree.to_string(), "0" ); assert_eq!( tree.pop_back(), None );
pub fn front_mut(&mut self) -> Option<Pin<&mut Node<T>>>
[src]
Returns a mutable reference to the first child of this node, or None if it has no child.
pub fn back_mut(&mut self) -> Option<Pin<&mut Node<T>>>
[src]
Returns a mutable reference to the last child of this node, or None if it has no child.
impl<T> Tree<T>
[src]
pub fn bfs_children_mut(&mut self) -> BfsForest<Splitted<IterMut<'_, T>>>
[src]
Provides a forward iterator with mutable references in a breadth-first manner, which iterates over all its descendants.
Examples
use trees::{tr, Tree}; let mut tree = Tree::from_tuple(( 0, (1,2,3), (4,5,6), )); tree.bfs_children_mut().iter .zip( 1.. ) .for_each( |(visit,nth)| *visit.data += 10 * nth ); assert_eq!( tree, Tree::<i32>::from_tuple(( 0, (11,32,43), (24,55,66), )));
pub fn bfs_mut(&mut self) -> BfsTree<Splitted<IterMut<'_, T>>>
[src]
Provides a forward iterator with mutable references in a breadth-first manner.
Examples
use trees::{tr, Tree}; let mut tree = Tree::from_tuple(( 0, (1,2,3), (4,5,6), )); tree.bfs_mut().iter .zip( 1.. ) .for_each( |(visit,nth)| *visit.data += 10 * nth ); assert_eq!( tree, Tree::<i32>::from_tuple(( 10, (21,42,53), (34,65,76), )));
pub fn into_bfs(self) -> BfsTree<Splitted<IntoIter<T>>>
[src]
Provides a forward iterator with owned data in a breadth-first manner.
Examples
use trees::{bfs,Size}; use trees::Tree; let tree = Tree::<i32>::from_tuple(( 0, (1,2,3), (4,5,6) )); let visits = tree.into_bfs().iter.collect::<Vec<_>>(); assert_eq!( visits, vec![ bfs::Visit{ data: 0, size: Size{ degree: 2, descendants: 6 }}, bfs::Visit{ data: 1, size: Size{ degree: 2, descendants: 2 }}, bfs::Visit{ data: 4, size: Size{ degree: 2, descendants: 2 }}, bfs::Visit{ data: 2, size: Size{ degree: 0, descendants: 0 }}, bfs::Visit{ data: 3, size: Size{ degree: 0, descendants: 0 }}, bfs::Visit{ data: 5, size: Size{ degree: 0, descendants: 0 }}, bfs::Visit{ data: 6, size: Size{ degree: 0, descendants: 0 }}, ]);
Methods from Deref<Target = Node<T>>
pub fn data(&self) -> &Tⓘ
[src]
Reference of its associated data.
pub fn has_no_child(&self) -> bool
[src]
Returns true
if Node
has no child nodes.
Examples
use trees::Tree; let mut tree = Tree::new(0); let mut root = tree.root_mut(); assert!( root.has_no_child() ); root.push_back( Tree::new(1) ); assert!( !root.has_no_child() );
pub fn degree(&self) -> usize
[src]
Returns the number of child nodes in Node
.
Examples
use trees::Tree; let mut tree = Tree::new(0); let mut root = tree.root_mut(); assert_eq!( root.degree(), 0 ); root.push_back( Tree::new(1) ); assert_eq!( root.degree(), 1 ); root.push_back( Tree::new(2) ); assert_eq!( root.degree(), 2 );
pub fn node_count(&self) -> usize
[src]
Returns the number of all child nodes in Node
, including itself.
Examples
use trees::Tree; let tree = Tree::<i32>::from_tuple(( 0, (1,2), (3,4) )); assert_eq!( tree.root().node_count(), 5 );
pub fn parent(&self) -> Option<&Node<T>>
[src]
Returns the parent node of this node, or None if it is the root node.
Examples
use trees::Tree; let tree = Tree::<i32>::from_tuple(( 0, 1, 2, 3 )); tree.root().iter().for_each( |child| { assert_eq!( child.parent(), Some( tree.root())) });
pub fn iter<'a, 's: 'a>(&'s self) -> Iter<'a, T>ⓘ
[src]
Provides a forward iterator over child Node
s
Examples
use trees::Tree; let mut tree = Tree::new(0); assert_eq!( tree.iter().next(), None ); tree.push_back( Tree::new(1) ); tree.push_back( Tree::new(2) ); let mut iter = tree.root().iter(); assert_eq!( iter.next(), Some( Tree::new(1).root() )); assert_eq!( iter.next(), Some( Tree::new(2).root() )); assert_eq!( iter.next(), None );
pub fn front(&self) -> Option<&Node<T>>
[src]
Returns the first child of this node, or None if it has no child.
pub fn back(&self) -> Option<&Node<T>>
[src]
Returns the last child of this node, or None if it has no child.
pub fn deep_clone(&self) -> Tree<T> where
T: Clone,
[src]
T: Clone,
Clones the node deeply and creates a new tree.
Examples
use trees::Tree; let tree = Tree::<i32>::from_tuple(( 0, (1,2,3), (4,5,6), (7,8,9), )); assert_eq!( tree.iter().nth(1).unwrap().deep_clone(), Tree::from_tuple(( 4,5,6 )));
pub fn deep_clone_forest(&self) -> Forest<T> where
T: Clone,
[src]
T: Clone,
Clones the node's descendant nodes as a forest.
Examples
use trees::{Tree,Forest}; let tree = Tree::<i32>::from_tuple(( 0, (1,2,3), (4,5,6), (7,8,9), )); assert_eq!( tree.iter().nth(1).unwrap().deep_clone_forest(), Forest::from_tuple(( 5,6 )));
pub fn bfs_children(&self) -> BfsForest<Splitted<Iter<'_, T>>>
[src]
Provides a forward iterator in a breadth-first manner, which iterates over all its descendants.
Examples
use trees::Tree; let tree = Tree::from_tuple(( 0, (1,2,3), (4,5,6), )); let visits = tree.root().bfs_children().iter .map( |visit| (*visit.data, visit.size.degree, visit.size.descendants )) .collect::<Vec<_>>(); assert_eq!( visits, vec![ (1, 2, 2), (4, 2, 2), (2, 0, 0), (3, 0, 0), (5, 0, 0), (6, 0, 0), ]);
pub fn bfs(&self) -> BfsTree<Splitted<Iter<'_, T>>>
[src]
Provides a forward iterator in a breadth-first manner.
Examples
use trees::Tree; let tree = Tree::from_tuple(( 0, (1,2,3), (4,5,6), )); let visits = tree.root().bfs().iter .map( |visit| (*visit.data, visit.size.degree, visit.size.descendants )) .collect::<Vec<_>>(); assert_eq!( visits, vec![ (0, 2, 6), (1, 2, 2), (4, 2, 2), (2, 0, 0), (3, 0, 0), (5, 0, 0), (6, 0, 0), ]);
Trait Implementations
impl<T: Clone> Clone for Tree<T>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for Tree<T>
[src]
impl<T> Deref for Tree<T>
[src]
impl<T: Display> Display for Tree<T>
[src]
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(mut self: Self, rhs: &'a Forest<T>) -> Tree<T>
[src]
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]
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(mut self: Self, rhs: &'a Tree<T>) -> Tree<T>
[src]
impl<'a, T: Clone> Div<&'a Tree<T>> for &'a Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Tree<T>
[src]
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]
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]
impl<T> Div<Forest<T>> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(mut self: Self, rhs: Forest<T>) -> Tree<T>
[src]
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]
impl<T> Div<Tree<T>> for Tree<T>
[src]
type Output = Tree<T>
The resulting type after applying the /
operator.
fn div(mut self: Self, rhs: Tree<T>) -> Tree<T>
[src]
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]
impl<T> Drop for Tree<T>
[src]
impl<T: Eq> Eq for Tree<T>
[src]
impl<T> Extend<Tree<T>> for RcNode<T>
[src]
fn extend<I: IntoIterator<Item = Tree<T>>>(&mut self, iter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<T, Iter> From<BfsTree<Iter>> for Tree<T> where
Iter: Iterator<Item = Visit<T>>,
[src]
Iter: Iterator<Item = Visit<T>>,
impl<T> From<Tree<T>> for TreeWalk<T>
[src]
impl<T> From<Tree<T>> for RcNode<T>
[src]
impl<T> From<TreeWalk<T>> for Tree<T>
[src]
impl<T: Hash> Hash for Tree<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> IntoIterator for Tree<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?
fn into_iter(self) -> IntoIter<T>ⓘ
[src]
impl<T> Neg for Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn neg(self) -> Forest<T>
[src]
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]
impl<T: Ord> Ord for Tree<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<Tree<T>> for Tree<T>
[src]
impl<T: PartialOrd> PartialOrd<Tree<T>> for Tree<T>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> Split for Tree<T>
[src]
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]
impl<'a, T: Clone> Sub<&'a Tree<T>> for &'a Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Forest<T>
[src]
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(mut self: Self, rhs: &'a Tree<T>) -> Self
[src]
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]
impl<T> Sub<Tree<T>> for Tree<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Forest<T>
[src]
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]
impl<T> Sub<Tree<T>> for Forest<T>
[src]
type Output = Forest<T>
The resulting type after applying the -
operator.
fn sub(mut self: Self, rhs: Tree<T>) -> Self
[src]
impl<'a, T: Clone> Sub<Tree<T>> for &'a Forest<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Tree<T>
[src]
impl<T> !Send for Tree<T>
[src]
impl<T> !Sync for Tree<T>
[src]
impl<T> Unpin for Tree<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> !UnwindSafe for Tree<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.