Struct avl::AvlTreeMap
source · [−]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
sourceimpl<K, V> AvlTreeMap<K, V>
impl<K, V> AvlTreeMap<K, V>
sourcepub fn new() -> Self where
K: Ord,
pub fn new() -> Self where
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> where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn get<Q>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Ord + ?Sized,
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> where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Ord + ?Sized,
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)> where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)> where
K: Borrow<Q>,
Q: Ord + ?Sized,
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 where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn contains_key<Q>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Ord + ?Sized,
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> where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn remove<Q>(&mut self, key: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Ord + ?Sized,
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)> where
K: Borrow<Q>,
Q: Ord + ?Sized,
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Ord + ?Sized,
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 where
K: Ord + Borrow<Q>,
Q: ?Sized + Ord,
pub fn split_off<Q>(&mut self, key: &Q) -> Self where
K: Ord + Borrow<Q>,
Q: ?Sized + Ord,
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>ⓘNotable traits for Range<'a, K, V>impl<'a, K, V> Iterator for Range<'a, K, V> type Item = (&'a K, &'a V);
where
K: Borrow<Q>,
R: RangeBounds<Q>,
Q: Ord + ?Sized,
pub fn range<Q, R>(&self, range: R) -> Range<'_, K, V>ⓘNotable traits for Range<'a, K, V>impl<'a, K, V> Iterator for Range<'a, K, V> type Item = (&'a K, &'a V);
where
K: Borrow<Q>,
R: RangeBounds<Q>,
Q: Ord + ?Sized,
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>ⓘNotable traits for RangeMut<'a, K, V>impl<'a, K, V> Iterator for RangeMut<'a, K, V> type Item = (&'a K, &'a mut V);
where
K: Borrow<Q>,
R: RangeBounds<Q>,
Q: Ord + ?Sized,
pub fn range_mut<Q, R>(&mut self, range: R) -> RangeMut<'_, K, V>ⓘNotable traits for RangeMut<'a, K, V>impl<'a, K, V> Iterator for RangeMut<'a, K, V> type Item = (&'a K, &'a mut V);
where
K: Borrow<Q>,
R: RangeBounds<Q>,
Q: Ord + ?Sized,
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>ⓘNotable traits for Iter<'a, K, V>impl<'a, K, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);
pub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);
Gets an iterator over the entries of the map, sorted by key.
sourcepub fn keys(&self) -> Keys<'_, K, V>ⓘNotable traits for Keys<'a, K, V>impl<'a, K, V> Iterator for Keys<'a, K, V> type Item = &'a K;
pub fn keys(&self) -> Keys<'_, K, V>ⓘNotable traits for Keys<'a, K, V>impl<'a, K, V> Iterator for Keys<'a, K, V> type Item = &'a K;
Gets an iterator over the keys of the map, in sorted order.
sourcepub fn values(&self) -> Values<'_, K, V>ⓘNotable traits for Values<'a, K, V>impl<'a, K, V> Iterator for Values<'a, K, V> type Item = &'a V;
pub fn values(&self) -> Values<'_, K, V>ⓘNotable traits for Values<'a, K, V>impl<'a, K, V> Iterator for Values<'a, K, V> type Item = &'a V;
Gets an iterator over the values of the map, in order by key.
Trait Implementations
sourceimpl<K: Clone, V: Clone> Clone for AvlTreeMap<K, V>
impl<K: Clone, V: Clone> Clone for AvlTreeMap<K, V>
sourceimpl<K, V> Debug for AvlTreeMap<K, V> where
K: Debug,
V: Debug,
impl<K, V> Debug for AvlTreeMap<K, V> where
K: Debug,
V: Debug,
sourceimpl<K, V> Drop for AvlTreeMap<K, V>
impl<K, V> Drop for AvlTreeMap<K, V>
sourceimpl<'a, K, V> Extend<(&'a K, &'a V)> for AvlTreeMap<K, V> where
K: Ord + Copy,
V: Copy,
impl<'a, K, V> Extend<(&'a K, &'a V)> for AvlTreeMap<K, V> where
K: Ord + Copy,
V: Copy,
sourcefn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (&'a K, &'a V)>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (&'a K, &'a V)>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K: Ord, V> Extend<(K, V)> for AvlTreeMap<K, V>
impl<K: Ord, V> Extend<(K, V)> for AvlTreeMap<K, V>
sourcefn 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)>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K: Ord, V> FromIterator<(K, V)> for AvlTreeMap<K, V>
impl<K: Ord, V> FromIterator<(K, V)> for AvlTreeMap<K, V>
sourceimpl<K: Hash, V: Hash> Hash for AvlTreeMap<K, V>
impl<K: Hash, V: Hash> Hash for AvlTreeMap<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a AvlTreeMap<K, V>
impl<'a, K, V> IntoIterator for &'a AvlTreeMap<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a mut AvlTreeMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut AvlTreeMap<K, V>
sourceimpl<K, V> IntoIterator for AvlTreeMap<K, V>
impl<K, V> IntoIterator for AvlTreeMap<K, V>
sourceimpl<K: Ord, V: Ord> Ord for AvlTreeMap<K, V>
impl<K: Ord, V: Ord> Ord for AvlTreeMap<K, V>
sourceimpl<K: PartialEq, V: PartialEq> PartialEq<AvlTreeMap<K, V>> for AvlTreeMap<K, V>
impl<K: PartialEq, V: PartialEq> PartialEq<AvlTreeMap<K, V>> for AvlTreeMap<K, V>
sourceimpl<K: PartialOrd, V: PartialOrd> PartialOrd<AvlTreeMap<K, V>> for AvlTreeMap<K, V>
impl<K: PartialOrd, V: PartialOrd> PartialOrd<AvlTreeMap<K, V>> for AvlTreeMap<K, V>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<K: Eq, V: Eq> Eq for AvlTreeMap<K, V>
impl<K, V> Send for AvlTreeMap<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for AvlTreeMap<K, V> where
K: Sync,
V: Sync,
Auto Trait Implementations
impl<K, V> RefUnwindSafe for AvlTreeMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Unpin for AvlTreeMap<K, V>
impl<K, V> UnwindSafe for AvlTreeMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more