pub struct AATreeMap<K, V> { /* private fields */ }
Implementations
sourceimpl<K, V> AATreeMap<K, V>
impl<K, V> AATreeMap<K, V>
sourcepub fn get<Q>(&self, key: &Q) -> Option<&V> where
K: Ord + Borrow<Q>,
Q: Ord + ?Sized,
pub fn get<Q>(&self, key: &Q) -> Option<&V> where
K: Ord + Borrow<Q>,
Q: Ord + ?Sized,
Returns a reference to the value corresponding to the key.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)> where
K: Ord + Borrow<Q>,
Q: Ord + ?Sized,
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)> where
K: Ord + Borrow<Q>,
Q: Ord + ?Sized,
Returns a reference to the key and value corresponding to the key.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);
sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V> where
K: Ord + Borrow<Q>,
Q: Ord + ?Sized,
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V> where
K: Ord + Borrow<Q>,
Q: Ord + ?Sized,
Returns a mutable reference to the value corresponding to the key.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
*map.get_mut(&1).unwrap() = "b";
assert_eq!(map.get(&1), Some(&"b"));
sourcepub fn first_key_value(&self) -> Option<(&K, &V)> where
K: Ord,
pub fn first_key_value(&self) -> Option<(&K, &V)> where
K: Ord,
Returns a reference to the first entry (that is, with the smallest key) in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.first_key_value(), None);
map.insert(3, "a");
map.insert(1, "b");
map.insert(2, "c");
assert_eq!(map.first_key_value(), Some((&1, &"b")));
pub fn smallest(&self) -> Option<(&K, &V)> where
K: Ord,
Use first_key_value() instead
sourcepub fn pop_first(&mut self) -> Option<(K, V)> where
K: Ord,
pub fn pop_first(&mut self) -> Option<(K, V)> where
K: Ord,
Returns and removes the first entry (that is, with the smallest key) in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.pop_first(), None);
map.insert(3, "a");
map.insert(1, "b");
map.insert(2, "c");
assert_eq!(map.pop_first(), Some((1, "b")));
assert_eq!(map.pop_first(), Some((2, "c")));
assert_eq!(map.pop_first(), Some((3, "a")));
assert_eq!(map.pop_first(), None);
pub fn pop_smallest(&mut self) -> Option<(K, V)> where
K: Ord,
Use pop_first() instead
sourcepub fn last_key_value(&self) -> Option<(&K, &V)> where
K: Ord,
pub fn last_key_value(&self) -> Option<(&K, &V)> where
K: Ord,
Returns a reference to the last entry (that is, with the largest key) in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.last_key_value(), None);
map.insert(1, "a");
map.insert(3, "b");
map.insert(2, "c");
assert_eq!(map.last_key_value(), Some((&3, &"b")));
pub fn largest(&self) -> Option<(&K, &V)> where
K: Ord,
Use last_key_value() instead
sourcepub fn pop_last(&mut self) -> Option<(K, V)> where
K: Ord,
pub fn pop_last(&mut self) -> Option<(K, V)> where
K: Ord,
Returns and removes the last entry (that is, with the largest key) in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.pop_last(), None);
map.insert(1, "a");
map.insert(3, "b");
map.insert(2, "c");
assert_eq!(map.pop_last(), Some((3, "b")));
assert_eq!(map.pop_last(), Some((2, "c")));
assert_eq!(map.pop_last(), Some((1, "a")));
assert_eq!(map.pop_last(), None);
pub fn pop_largest(&mut self) -> Option<(K, V)> where
K: Ord,
sourcepub fn first_key_value_at_or_after<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn first_key_value_at_or_after<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns a reference to the first entry with a key greater than or equal to k
in
the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.first_key_value_at_or_after(&15), None);
map.insert(10, "a");
map.insert(30, "b");
map.insert(20, "c");
assert_eq!(map.first_key_value_at_or_after(&15), Some((&20, &"c")));
pub fn smallest_geq_than<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Use first_key_value_at_or_after() instead
sourcepub fn first_key_value_mut_at_or_after<Q>(
&mut self,
k: &Q
) -> Option<(&K, &mut V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn first_key_value_mut_at_or_after<Q>(
&mut self,
k: &Q
) -> Option<(&K, &mut V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns a mutable reference to the first entry with a key greater than or equal
to k
in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.first_key_value_mut_at_or_after(&15), None);
map.insert(10, "a");
map.insert(30, "b");
map.insert(20, "c");
let value: &mut &str = map.first_key_value_mut_at_or_after(&15).unwrap().1;
assert_eq!(*value, "c");
*value = "d";
assert_eq!(map.first_key_value_at_or_after(&15), Some((&20, &"d")));
pub fn smallest_geq_than_mut<Q>(&mut self, k: &Q) -> Option<(&K, &mut V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Use first_key_value_mut_at_or_after() instead
sourcepub fn last_key_value_at_or_before<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn last_key_value_at_or_before<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns a reference to the last entry with a key smaller than or equal to k
in
the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.last_key_value_at_or_before(&25), None);
map.insert(10, "a");
map.insert(30, "b");
map.insert(20, "c");
assert_eq!(map.last_key_value_at_or_before(&25), Some((&20, &"c")));
pub fn largest_leq_than<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Use last_key_value_at_or_before() instead
sourcepub fn last_key_value_mut_at_or_before<Q>(
&mut self,
k: &Q
) -> Option<(&K, &mut V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn last_key_value_mut_at_or_before<Q>(
&mut self,
k: &Q
) -> Option<(&K, &mut V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns a mutable reference to the last entry with a key smaller than or equal to
k
in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.last_key_value_mut_at_or_before(&25), None);
map.insert(10, "a");
map.insert(30, "b");
map.insert(20, "c");
let value: &mut &str = map.last_key_value_mut_at_or_before(&25).unwrap().1;
assert_eq!(*value, "c");
*value = "d";
assert_eq!(map.last_key_value_at_or_before(&25), Some((&20, &"d")));
pub fn largest_leq_than_mut<Q>(&mut self, k: &Q) -> Option<(&K, &mut V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Use last_key_value_mut_at_or_before() instead
sourceimpl<K, V> AATreeMap<K, V>
impl<K, V> AATreeMap<K, V>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct a new, empty AA-Tree based map.
Example
let map = AATreeMap::new();
assert!(map.is_empty());
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
Example
let mut map = AATreeMap::new();
assert_eq!(map.len(), 0);
map.insert(1, "a");
assert_eq!(map.len(), 1);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
Example
let mut map = AATreeMap::new();
assert!(map.is_empty());
map.insert(1, "a");
assert!(!map.is_empty());
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all elements.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
map.clear();
assert!(map.is_empty());
sourcepub fn iter(&self) -> AAIter<'_, Entry<K, V>, (&K, &V)>ⓘNotable traits for AAIter<'a, C, T>impl<'a, C, T> Iterator for AAIter<'a, C, T> where
&'a C: IterContent<T>, type Item = T;
pub fn iter(&self) -> AAIter<'_, Entry<K, V>, (&K, &V)>ⓘNotable traits for AAIter<'a, C, T>impl<'a, C, T> Iterator for AAIter<'a, C, T> where
&'a C: IterContent<T>, type Item = T;
&'a C: IterContent<T>, type Item = T;
Creates an iterator over this map that visits all entries with the keys in ascending order.
sourcepub fn keys(&self) -> impl Iterator<Item = &K>
pub fn keys(&self) -> impl Iterator<Item = &K>
Creates an iterator visiting all the keys, in sorted order.
sourcepub fn values(&self) -> impl Iterator<Item = &V>
pub fn values(&self) -> impl Iterator<Item = &V>
Creates an iterator visiting all the values, in sorted order.
sourcepub fn into_keys(self) -> impl Iterator<Item = K>
pub fn into_keys(self) -> impl Iterator<Item = K>
Creates a consuming iterator visiting all the keys, in sorted order. The map cannot be used after calling this.
sourcepub fn into_values(self) -> impl Iterator<Item = V>
pub fn into_values(self) -> impl Iterator<Item = V>
Creates a consuming iterator visiting all the values, in order by key. The map cannot be used after calling this.
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,
Insert a new element into the map, or overwrite an existing element with the same key. If a value was overwritten, the old value will be returned.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
map.insert(1, "b");
assert_eq!(map.get(&1), Some(&"b"));
sourcepub fn contains_key<Q>(&self, k: &Q) -> bool where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn contains_key<Q>(&self, k: &Q) -> bool where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Check if a key is contained within this map.
Example
let mut map = AATreeMap::new();
assert!(!map.contains_key(&1));
map.insert(1, "a");
assert!(map.contains_key(&1));
sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn remove<Q>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Remove a key from the map if it exists, and return the value that was previously stored in the map for that key.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
assert_eq!(map.get(&1), Some(&"a"));
let value = map.remove(&1);
assert_eq!(value, Some("a"));
assert_eq!(map.get(&1), None);
sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)> where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Remove a key from the map if it exists, and return the key and the value that was previously stored in the map for that key.
Example
let mut map = AATreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
assert_eq!(map.get(&1), Some(&"a"));
let value = map.remove(&1);
assert_eq!(value, Some("a"));
assert_eq!(map.get(&1), None);
Trait Implementations
sourceimpl<K: Ord, V> FromIterator<(K, V)> for AATreeMap<K, V>
impl<K: Ord, V> FromIterator<(K, V)> for AATreeMap<K, V>
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
Creates a value from an iterator. Read more
sourceimpl<'a, K, V> IntoIterator for &'a AATreeMap<K, V>
impl<'a, K, V> IntoIterator for &'a AATreeMap<K, V>
Auto Trait Implementations
impl<K, V> RefUnwindSafe for AATreeMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for AATreeMap<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for AATreeMap<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for AATreeMap<K, V>
impl<K, V> UnwindSafe for AATreeMap<K, V> where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more