pub struct AVL<K: Ord, V> { /* private fields */ }
Expand description
An AVL balanced tree with owned nodes.
Implementations§
Source§impl<K: Ord, V> AVL<K, V>
impl<K: Ord, V> AVL<K, V>
Sourcepub fn add(&mut self, k: K, v: V)
pub fn add(&mut self, k: K, v: V)
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);
Sourcepub fn insert(&mut self, k: K, v: V)
pub fn insert(&mut self, k: K, v: V)
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);
Sourcepub fn set(&mut self, k: K, v: V)
pub fn set(&mut self, k: K, v: V)
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));
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
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);
Sourcepub fn iter<'a>(&'a self) -> Iter<'a, K, V>
pub fn iter<'a>(&'a self) -> Iter<'a, K, V>
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)));
Sourcepub fn contains(&self, k: &K) -> bool
pub fn contains(&self, k: &K) -> bool
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));
Sourcepub fn remove(&mut self, k: &K) -> Option<V>
pub fn remove(&mut self, k: &K) -> Option<V>
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);
Sourcepub fn peek_root<'a>(&'a self) -> Option<(&'a K, &'a V)>
pub fn peek_root<'a>(&'a self) -> Option<(&'a K, &'a V)>
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)));
Sourcepub fn is_balanced_tree(&self) -> bool
pub fn is_balanced_tree(&self) -> bool
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);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
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);
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
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);
Trait Implementations§
Source§impl<K: Ord, V> IntoIterator for AVL<K, V>
impl<K: Ord, V> IntoIterator for AVL<K, V>
impl<K: Ord + Send, V: Send> Send for AVL<K, V>
impl<K: Ord + Sync, V: Sync> Sync for AVL<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for AVL<K, V>
impl<K, V> RefUnwindSafe for AVL<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Unpin for AVL<K, V>
impl<K, V> UnwindSafe for AVL<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more