[][src]Struct vec_tree::VecTree

pub struct VecTree<T> { /* fields omitted */ }

Methods

impl<T> VecTree<T>
[src]

Constructs a new, empty VecTree.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::<usize>::new();

Constructs a new, empty VecTree<T> with the specified capacity.

The VecTree<T> will be able to hold n elements without further allocation.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::with_capacity(10);
let root = tree.try_insert_root(0).unwrap();

// These insertions will not require further allocation.
for i in 1..10 {
    assert!(tree.try_insert(i, root).is_ok());
}

// But now we are at capacity, and there is no more room.
assert!(tree.try_insert(99, root).is_err());

Allocate space for additional_capacity more elements in the tree.

Panics

Panics if this causes the capacity to overflow.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::with_capacity(10);
tree.reserve(5);
assert_eq!(tree.capacity(), 15);

Attempts to insert value into the tree using existing capacity.

This method will never allocate new capacity in the tree.

If insertion succeeds, then the value's index is returned. If insertion fails, then Err(value) is returned to give ownership of value back to the caller.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::new();
let root = tree.insert_root(0);

match tree.try_insert(42, root) {
    Ok(idx) => {
        // Insertion succeeded.
        assert_eq!(tree[idx], 42);
    }
    Err(x) => {
        // Insertion failed.
        assert_eq!(x, 42);
    }
};

Insert value into the tree, allocating more capacity if necessary.

The value's associated index in the tree is returned.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::with_capacity(1);
assert_eq!(tree.capacity(), 1);

let root = tree.insert_root(0);

let idx = tree.insert(42, root);
assert_eq!(tree[idx], 42);
assert_eq!(tree.capacity(), 2);

Remove the element at index node_id from the tree.

If the element at index node_id is still in the tree, then it is returned. If it is not in the tree, then None is returned.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::new();
let root = tree.insert_root(42);

assert_eq!(tree.remove(root), Some(42));
assert_eq!(tree.remove(root), None);

Is the element at index node_id in the tree?

Returns true if the element at node_id is in the tree, false otherwise.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::new();
let root = tree.insert_root(0);

assert!(tree.contains(root));
tree.remove(root);
assert!(!tree.contains(root));

Get a shared reference to the element at index node_id if it is in the tree.

If the element at index node_id is not in the tree, then None is returned.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::new();
let root = tree.insert_root(42);

assert_eq!(tree.get(root), Some(&42));
tree.remove(root);
assert!(tree.get(root).is_none());

Get an exclusive reference to the element at index node_id if it is in the tree.

If the element at index node_id is not in the tree, then None is returned.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::new();
let root = tree.insert_root(42);

*tree.get_mut(root).unwrap() += 1;
assert_eq!(tree.remove(root), Some(43));
assert!(tree.get_mut(root).is_none());

Get the capacity of this tree.

The capacity is the maximum number of elements the tree can hold without further allocation, including however many it currently contains.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::with_capacity(10);
let root = tree.insert_root(0);

// `try_insert` does not allocate new capacity.
for i in 1..10 {
    assert!(tree.try_insert(i, root).is_ok());
    assert_eq!(tree.capacity(), 10);
}

// But `insert` will if the root is already at capacity.
tree.insert(11, root);
assert!(tree.capacity() > 10);

Clear all the items inside the tree, but keep its allocation.

Examples

use vec_tree::VecTree;

let mut tree = VecTree::with_capacity(1);
let root = tree.insert_root(42);
tree.insert(43, root); // The capacity is doubled when reached.

tree.clear();
assert_eq!(tree.capacity(), 2);

Return an iterator of references to this node’s parent.

Important traits for ChildrenIter<'a, T>

Return an iterator of references to this node’s children.

Important traits for PrecedingSiblingsIter<'a, T>

Return an iterator of references to this node and the siblings before it.

Call .next().unwrap() once on the iterator to skip the node itself.

Important traits for FollowingSiblingsIter<'a, T>

Return an iterator of references to this node and the siblings after it.

Call .next().unwrap() once on the iterator to skip the node itself.

Important traits for AncestorsIter<'a, T>

Return an iterator of references to this node and its ancestors.

Call .next().unwrap() once on the iterator to skip the node itself.

Important traits for DescendantsIter<'a, T>

Return an iterator of references to this node and its descendants, in tree order.

Parent nodes appear before the descendants. Call .next().unwrap() once on the iterator to skip the node itself.

Important traits for DescendantsWithDepthIter<'a, T>

Return an iterator of references to this node and its descendants, with deoth in the tree, in tree order.

Parent nodes appear before the descendants. Call .next().unwrap() once on the iterator to skip the node itself.

Trait Implementations

impl<T> Default for VecTree<T>
[src]

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

impl<T> Index<Index> for VecTree<T>
[src]

The returned type after indexing.

impl<T> IndexMut<Index> for VecTree<T>
[src]

Auto Trait Implementations

impl<T> Send for VecTree<T> where
    T: Send

impl<T> Sync for VecTree<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]