Struct avl_tree::tree::AVLTree [] [src]

pub struct AVLTree<K: Ord + Copy, D> {
    pub root: Option<Box<Node<K, D>>>,
}

Fields

Methods

impl<K: Ord + Copy, D> AVLTree<K, D>
[src]

This function will construct a new empty AVLTree.

Examples

extern crate avl_tree;
let mut t=avl_tree::AVLTree::<u64,i32>::new();

This function will insert the key,value pair into the tree, overwriting the old data if the key is allready part of the tree.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
assert_eq!(t.get(2), Some(&25));
t.insert(2,30);
assert_eq!(t.get(2), Some(&30));

This function will remove the key,value pair from the tree, doing nothing if the key is not part of the tree.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
t.delete(2);
assert!(t.empty());
t.delete(3);
assert!(t.empty());

This function will return the Some(data) stored under the given key or None if the key is not known.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
assert_eq!(t.get(2), Some(&25));
assert_eq!(t.get(3), None);

This function will return the data stored under the given key or the default if the key is not known.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
assert_eq!(t.get_or(2,&2000), &25);
assert_eq!(t.get_or(3,&2000), &2000);

This function will return true if the tree contains the given key, false otherwise

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
assert!(!t.contains(3));
assert!(t.contains(2));

This function will return true if the tree is empty, false otherwise.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
assert!(t.empty());
t.insert(2,25);
assert!(!t.empty());

This function will return the key/value pair with the smallest key in the tree, or None if the tree is empty.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
t.insert(3,50);
assert_eq!(t.min().unwrap().0, &2);
assert_eq!(t.min().unwrap().1, &25);

This function will return the key/value pair with the biggest key in the tree, or None if the tree is empty.

Examples

let mut t=avl_tree::AVLTree::<u64,i32>::new();
t.insert(2,25);
t.insert(3,50);
assert_eq!(t.max().unwrap().0, &3);
assert_eq!(t.max().unwrap().1, &50);

This function will return a read only iterator for all (key,value) pairs in the tree.

Examples

for (key,val) in t.iter() {
    println!("{} -> {}",key,val)
}

This function will return a read only iterator for all (key,value) pairs between the two bounds (which can be inclusive, exclusive or unbounded).

Examples

#![feature(collections_bound)]
use std::collections::Bound;
//[...]
for (key,val) in t.range(Bound::Excluded(32), Bound::Excluded(38)) {
    println!("{} -> {}",key,val)
}