This library is a Rust implementation of one of self-balancing tree data structures - AVL Tree. Developed as part of the assignments of great MIPT Rust course by Alexander Stanovoy.
The available methods repeat those of the HashMap data type with some additional functionality.
All operations are performed in O(logn)
time.
- Create a variable of type
AVLTreeMap<K: Ord, V>
.
let mut tree_map = AVLTreeMap::new();
- Insert a new node. Returns an
Option<V>
.
tree_map.insert("hello", 41); // -> None
tree_map.insert("hello", 1); // -> Some(41)
- Delete node. Returns
Option<(K, V)>
orOption<V>
tree_map.remove_entry("hello"); // -> Some(("hello", 1))
or
tree_map.remove("hello"); // -> Some(1)
- Check if a tree contains a node with some key.
tree_map.contains_key("hello"); // -> false
- Get key/value pair
tree_map.insert("hello", 42);
tree_map.get_key_value("hello"); // -> Some(("hello", &42))
- Find n-th node by order, 0-indexed
tree_map.nth_key_value(0); // -> Some(("hello", &42))
- Get the node value by key
tree_map.get("hello"); // -> Some(&42)
Run tests with build optimizations.
cargo build --release
cargo test --release