[][src]Crate trees

General purpose tree library. See the trees book for more.

Examples

The code below construct the following tree in different ways:

.............
.     0     .
.   /   \   .
.  1     4  .
. / \   / \ .
.2   3 5   6.
.............

Example of tr notations for building trees

use trees::tr;

let tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );

Example of tuple notations for building trees

let tree = trees::Tree::<i32>::from_tuple(( 0, (1,2,3), (4,5,6) ));

Example of building trees step by step

use trees::Tree;

let mut tree = Tree::new(0);

let mut root = tree.root_mut();
root.push_back( Tree::new(1) );
root.push_back( Tree::new(4) );

let mut children = root.iter_mut();

let mut node_1 = children.next().unwrap();
node_1.push_back( Tree::new(2) );
node_1.push_back( Tree::new(3) );

let mut node_4 = children.next().unwrap();
node_4.push_back( Tree::new(5) );
node_4.push_back( Tree::new(6) );

Overview of features

  1. Step-by-step creating, reading, updating, deleting and iterating nodes with assocated data items.

  2. Compact notations to express trees: -,/ encoded or tuple encoded trees.

  3. Depth first search cursor.

  4. Breadth first search iterators.

  5. Trees can be built by stages, with nodes stored scatteredly among memory.

  6. Trees can be built once through, with nodes stored contiguously.

  7. Support exclusive ownership with static borrow check.

  8. Support shared ownership with dynamic borrow check.

Re-exports

pub use tuple::TupleForest;
pub use tuple::TupleTree;
pub use size::Size;
pub use tree::Tree;
pub use forest::Forest;
pub use node::Node;
pub use iter::Iter;
pub use iter::IterMut;
pub use into_iter::IntoIter;
pub use walk::TreeWalk;
pub use walk::ForestWalk;
pub use notation::tr;
pub use notation::fr;
pub use iter_rc::IterRc;
pub use rc::RcNode;
pub use rc::WeakNode;

Modules

bfs

Breadth first search.

forest

Composed of a list of Nodes as its children.

into_iter

Forest's owning iterator.

iter

Iterators of Tree/Forest, returned by iter() or iter_mut().

iter_rc

Iterators of RcNode, returned by iter_rc().

node

Composed of data and a list of its child Nodes.

notation

Operator overloading of - and / for constructing tree expression.

rc

Reference-counting nodes.

size

size of a tree/forest/node, including degree and descendant node count

tree

Composed of a root Node and a list of its child Nodes.

tuple

Traits for implementing tuple notations

walk

Depth first search in Tree/Node/Forest.