Struct ABtree::AVL [−][src]
pub struct AVL<K: Ord, V> { /* fields omitted */ }
Expand description
An AVL balanced tree with owned nodes.
Implementations
Adding key-value pair into the tree
Example
use ABtree::AVL;
let mut t = AVL::<i32, i32>::new();
t.add(2, 3);
assert_eq!(t.len(), 1);
Adding key-value pair into the tree this method is an alias of method add
Example
use ABtree::AVL;
let mut t = AVL::<i32, i32>::new();
t.insert(2, 3);
assert_eq!(t.len(), 1);
Setting a key-value pair if the key exists it will update the value otherwise it will insert the key-value into the tree
Example
use ABtree::AVL;
let mut t = AVL::<i32, i32>::new();
t.set(2, 2);
t.set(2, 31);
assert_eq!(t.get(&2), Some(&31));
Get the length of this tree
Example
use ABtree::AVL;
let mut t = AVL::<i32, i32>::new();
t.insert(2, 2);
t.insert(3, 3);
assert_eq!(t.len(), 2);
Provides a forward iterator.
Examples
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
let mut iter = t.iter();
assert_eq!(iter.next(), Some((&0, &0)));
assert_eq!(iter.next(), Some((&1, &1)));
assert_eq!(iter.next_back(), Some((&2, &2)));
Containment check
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
assert!(t.contains(&1));
Removing key-value pair
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
assert_eq!(t.remove(&1), Some(1));
assert_eq!(t.len(), 2);
Peeking the root node
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
assert_eq!(t.peek_root(), Some((&1, &1)));
To check if shis tree is balanced
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
assert_eq!(t.is_balanced_tree(), true);
To check if shis tree is empty
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
assert_eq!(t.is_empty(), false);
Removes all elements from the AVL tree
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
t.clear();
assert_eq!(t.len(), 0);
Get the value by key
Example
use ABtree::AVL;
let mut t: AVL<u32, u32> = AVL::new();
t.insert(0, 0);
t.insert(1, 1);
t.insert(2, 2);
assert_eq!(t.get(&1), Some(&1));
Trait Implementations
Drop
Auto Trait Implementations
impl<K, V> RefUnwindSafe for AVL<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> UnwindSafe for AVL<K, V> where
K: UnwindSafe + RefUnwindSafe,
V: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more