Struct ABtree::AVL[][src]

pub struct AVL<K: Ord, V> { /* fields omitted */ }
Expand description

An AVL balanced tree with owned nodes.

Implementations

Create an empty AVL tree

Examples
use ABtree::AVL;

let t = AVL::<i32, i32>::new();

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));

Get a mutable reference of 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);
let v = t.get_mut(&2);
v.map(|i| *i += 10);
assert_eq!(t.get(&2), Some(&12))

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Drop

Executes the destructor for this type. Read more

Creates a value from an iterator. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

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

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.