Struct trees::Node
[−]
[src]
pub struct Node<T> { pub data: T, // some fields omitted }
Tree node implemented in singly-linked-children / circularly-linked-siblings.
Fields
data: T
Methods
impl<T> Node<T>
[src]
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> 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: PartialEq> PartialEq for Node<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 Node<T>
[src]
impl<T: PartialOrd> PartialOrd for Node<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 Node<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> 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> ToOwned for Node<T>
[src]
type Owned = Tree<T>
fn to_owned(&self) -> Tree<T>
[src]
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut Self::Owned)
[src]
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> Drop for Node<T>
[src]
impl<T: Hash> Hash for Node<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 Node<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Display> Display for Node<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more