pub struct AATreeMap<K, V> { /* private fields */ }

Implementations

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

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

Gets the given key’s corresponding entry, allowing for in-place manipulation of the entry as well as inserting an entry with that key if it does not exist yet.

Example
let mut map = AATreeMap::new();
let entry = map.entry(1);
assert!(matches!(entry, Entry::Vacant(_)));
entry.or_insert('a');
assert_eq!(map.get(&1), Some(&'a'));

let entry = map.entry(1);
assert!(matches!(entry, Entry::Occupied(_)));
entry.and_modify(|value| *value = 'b');
assert_eq!(map.get(&1), Some(&'b'));

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

pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>where
    K: Ord + Debug,
    V: Debug,

Gets the first entry (that is, with the smallest key) in the map, allowing for in-place manipulation of the entry.

Example
let mut map = AATreeMap::new();
let entry = map.first_entry();
assert!(entry.is_none());

map.insert(1, 'a');
map.insert(3, 'c');
println!("{map:?}");

let Some(mut entry) = map.first_entry() else { unreachable!() };
*entry.get_mut() = 'b';
assert_eq!(map.get(&1), Some(&'b'));
assert_eq!(map.get(&3), Some(&'c'));

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

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

pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>where
    K: Ord,

Gets the last entry (that is, with the largest key) in the map, allowing for in-place manipulation of the entry.

Example
let mut map = AATreeMap::new();
let entry = map.last_entry();
assert!(entry.is_none());

map.insert(1, 'a');
map.insert(3, 'c');

let Some(mut entry) = map.last_entry() else { unreachable!() };
*entry.get_mut() = 'b';
assert_eq!(map.get(&1), Some(&'a'));
assert_eq!(map.get(&3), Some(&'b'));

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

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

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

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) = map.first_key_value_mut_at_or_after(&15).unwrap();
assert_eq!(*value, "c");
*value = "d";
assert_eq!(map.first_key_value_at_or_after(&15), Some((&20, &"d")));

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

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) = map.last_key_value_mut_at_or_before(&25).unwrap();
assert_eq!(*value, "c");
*value = "d";
assert_eq!(map.last_key_value_at_or_before(&25), Some((&20, &"d")));

Construct a new, empty AA-Tree based map.

Example
let map = AATreeMap::new();
assert!(map.is_empty());

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

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

Clears the map, removing all elements.

Example
let mut map = AATreeMap::new();
map.insert(1, "a");
map.clear();
assert!(map.is_empty());

Creates an iterator over this map that visits all entries with the keys in ascending order.

Creates an iterator visiting all the keys, in sorted order.

Creates an iterator visiting all the values, in sorted order.

Creates a consuming iterator visiting all the keys, in sorted order. The map cannot be used after calling this.

Creates a consuming iterator visiting all the values, in order by key. The map cannot be used after calling this.

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

Moves all elements from other into self, leaving other empty.

Examples
use std::collections::BTreeMap;

let mut a = BTreeMap::new();
a.insert(1, "a");
a.insert(2, "b");
a.insert(3, "c");

let mut b = BTreeMap::new();
b.insert(3, "d");
b.insert(4, "e");
b.insert(5, "f");

a.append(&mut b);

assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);

assert_eq!(a[&1], "a");
assert_eq!(a[&2], "b");
assert_eq!(a[&3], "d");
assert_eq!(a[&4], "e");
assert_eq!(a[&5], "f");

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

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

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Converts to this type from the input type.
Converts to this type from the input type.
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
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
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. 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
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.