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

Methods

impl<T> Node<T>
[src]

[src]

Append the given trees at the end of the Node's children list.

[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) );

[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 );

[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) );

[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>
[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>
[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>
[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) );

[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]

[src]

Extends a collection with the contents of an iterator. Read more

impl<T: PartialEq> PartialEq for Node<T>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<T: Eq> Eq for Node<T>
[src]

impl<T: PartialOrd> PartialOrd for Node<T>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<T> Borrow<Node<T>> for Tree<T>
[src]

[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<Node<T>> for Tree<T>
[src]

[src]

Mutably borrows from an owned value. Read more

impl<T: Clone> ToOwned for Node<T>
[src]

[src]

Creates owned data from borrowed data, usually by cloning. Read more

[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]

[src]

Executes the destructor for this type. Read more

impl<T: Hash> Hash for Node<T>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Debug> Debug for Node<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: Display> Display for Node<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: Send> Send for Node<T>
[src]

impl<T: Sync> Sync for Node<T>
[src]