Struct coll::persistent::RbTree [] [src]

pub struct RbTree<T: PartialEq + PartialOrd> { /* fields omitted */ }

Methods

impl<T: PartialEq + PartialOrd> RbTree<T>
[src]

Creates a new, empty, red-black tree.

Inserts an item into a new copy of the existing Tree.

Examples

use coll::persistent::RbTree;
let tree_one = RbTree::new();
let tree_two = tree_one.insert(1);
let tree_three = tree_two.insert(2);
assert!(tree_one != tree_two);
assert!(tree_two != tree_three);
assert!(tree_three != tree_one);

Gets the length of the current tree.

Examples

use coll::persistent::RbTree;
let tree = RbTree::new().insert(4).insert(2).insert(3).insert(1);
assert_eq!(tree.len(), 4);

Checks the tree for the presence of a given T.

Examples

use coll::persistent::RbTree;
let tree = RbTree::new().insert(1).insert(2).insert(3);
assert!(tree.contains(1));
assert!(tree.contains(2));
assert!(tree.contains(3));
assert_eq!(tree.contains(4), false);

Returns true if the collection is empty.

Examples

use coll::persistent::RbTree;
let tree: RbTree<i32> = RbTree::new();
assert!(tree.is_empty());

let tree = tree.insert(1);
assert!(tree.is_empty() == false);

Returns an in-order iterator over the nodes in the tree.

The iterator uses O(log n) space for node traversal.

Examples

use coll::persistent::RbTree;
let tree = RbTree::new().insert(4).insert(2).insert(1).insert(3)
                        .insert(8).insert(6).insert(5).insert(7);
let mut iter = tree.iter();
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), Some(&3));
assert_eq!(iter.next(), Some(&4));
assert_eq!(iter.next(), Some(&5));
assert_eq!(iter.next(), Some(&6));
assert_eq!(iter.next(), Some(&7));
assert_eq!(iter.next(), Some(&8));
assert_eq!(iter.next(), None);

Trait Implementations

impl<T: Debug + PartialEq + PartialOrd> Debug for RbTree<T>
[src]

Formats the value using the given formatter.

impl<T: PartialEq + PartialEq + PartialOrd> PartialEq for RbTree<T>
[src]

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

This method tests for !=.

impl<T: Clone + PartialEq + PartialOrd> Clone for RbTree<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more