pub struct AvlTreeMap<K, V> { /* private fields */ }
Expand description
An ordered map implemented with an AVL tree.
use avl::AvlTreeMap;
let mut map = AvlTreeMap::new();
map.insert(0, "zero");
map.insert(1, "one");
map.insert(2, "two");
assert_eq!(map.get(&1), Some(&"one"));
map.remove(&1);
assert!(map.get(&1).is_none());
Implementations§
Source§impl<K, V> AvlTreeMap<K, V>
impl<K, V> AvlTreeMap<K, V>
Sourcepub fn new() -> Selfwhere
K: Ord,
pub fn new() -> Selfwhere
K: Ord,
Creates an empty map. No memory is allocated until the first item is inserted.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Returns references to the key-value pair corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the key is in the map, else false.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Ord,
pub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Ord,
Inserts a key-value pair into the map. Returns None if the key is not in the map. Updates the value if the key is already in the map and returns the old value.
Sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>where
K: Ord,
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>where
K: Ord,
Gets the map entry of given key for in-place manipulation.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes a key from the map. Returns the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes a key from the map. Returns the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn append(&mut self, other: &mut Self)where
K: Ord,
pub fn append(&mut self, other: &mut Self)where
K: Ord,
Moves all elements from other into self, leaving other empty.
Sourcepub fn split_off<Q>(&mut self, key: &Q) -> Self
pub fn split_off<Q>(&mut self, key: &Q) -> Self
Splits the collection into two at the given key. Returns everything after the given key, including the key.
Sourcepub fn range<Q, R>(&self, range: R) -> Range<'_, K, V> ⓘ
pub fn range<Q, R>(&self, range: R) -> Range<'_, K, V> ⓘ
Gets an iterator over a range of elements in the map, in order by key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
§Panics
Panics if range start > end
.
Panics if range start == end
and both bounds are Excluded
.
Sourcepub fn range_mut<Q, R>(&mut self, range: R) -> RangeMut<'_, K, V> ⓘ
pub fn range_mut<Q, R>(&mut self, range: R) -> RangeMut<'_, K, V> ⓘ
Gets a mutable iterator over a range of elements in the map, in order by key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
§Panics
Panics if range start > end
.
Panics if range start == end
and both bounds are Excluded
.
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Gets an iterator over the entries of the map, sorted by key.
Sourcepub fn keys(&self) -> Keys<'_, K, V> ⓘ
pub fn keys(&self) -> Keys<'_, K, V> ⓘ
Gets an iterator over the keys of the map, in sorted order.
Sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
Gets an iterator over the values of the map, in order by key.
Sourcepub fn values_mut(&self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&self) -> ValuesMut<'_, K, V> ⓘ
Gets a mutable iterator over the values of the map, in order by key.
Trait Implementations§
Source§impl<K, V> Debug for AvlTreeMap<K, V>
impl<K, V> Debug for AvlTreeMap<K, V>
Source§impl<K, V> Drop for AvlTreeMap<K, V>
impl<K, V> Drop for AvlTreeMap<K, V>
Source§impl<'a, K, V> Extend<(&'a K, &'a V)> for AvlTreeMap<K, V>
impl<'a, K, V> Extend<(&'a K, &'a V)> for AvlTreeMap<K, V>
Source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<K: Ord, V> Extend<(K, V)> for AvlTreeMap<K, V>
impl<K: Ord, V> Extend<(K, V)> for AvlTreeMap<K, V>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)