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§

source§

impl<K, V> AvlTreeMap<K, V>

source

pub fn new() -> Selfwhere K: Ord,

Creates an empty map. No memory is allocated until the first item is inserted.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source

pub fn len(&self) -> usize

Returns the number of elements in the map.

source

pub fn clear(&mut self)

Clears the map, deallocating all memory.

source

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.

source

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.

source

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.

source

pub fn contains_key<Q>(&self, key: &Q) -> boolwhere 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.

source

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.

source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>where K: Ord,

Gets the map entry of given key for in-place manipulation.

source

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.

source

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.

source

pub fn append(&mut self, other: &mut Self)where K: Ord,

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

source

pub fn split_off<Q>(&mut self, key: &Q) -> Selfwhere 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.

source

pub fn range<Q, R>(&self, range: R) -> Range<'_, K, 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.

source

pub fn range_mut<Q, R>(&mut self, range: R) -> RangeMut<'_, K, 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.

source

pub fn iter(&self) -> Iter<'_, K, V>

Gets an iterator over the entries of the map, sorted by key.

source

pub fn keys(&self) -> Keys<'_, K, V>

Gets an iterator over the keys of the map, in sorted order.

source

pub fn values(&self) -> Values<'_, K, V>

Gets an iterator over the values of the map, in order by key.

source

pub fn values_mut(&self) -> ValuesMut<'_, K, V>

Gets a mutable iterator over the values of the map, in order by key.

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Gets a mutable iterator over the entries of the map, sorted by key.

Trait Implementations§

source§

impl<K: Clone, V: Clone> Clone for AvlTreeMap<K, V>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K, V> Debug for AvlTreeMap<K, V>where K: Debug, V: Debug,

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Ord, V> Default for AvlTreeMap<K, V>

source§

fn default() -> Self

Creates an empty map.

source§

impl<K, V> Drop for AvlTreeMap<K, V>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, K, V> Extend<(&'a K, &'a V)> for AvlTreeMap<K, V>where K: Ord + Copy, V: Copy,

source§

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
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

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

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<K: Ord, V> FromIterator<(K, V)> for AvlTreeMap<K, V>

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<K: Hash, V: Hash> Hash for AvlTreeMap<K, V>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<Q, K, V> Index<&Q> for AvlTreeMap<K, V>where K: Ord + Borrow<Q>, Q: Ord + ?Sized,

source§

fn index(&self, key: &Q) -> &V

Returns a reference to the value for the given key.

Panics

Panics if the key is not present in the map.

§

type Output = V

The returned type after indexing.
source§

impl<'a, K, V> IntoIterator for &'a AvlTreeMap<K, V>

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K, V> IntoIterator for &'a mut AvlTreeMap<K, V>

§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> IntoIterator for AvlTreeMap<K, V>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K: Ord, V: Ord> Ord for AvlTreeMap<K, V>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<K: PartialEq, V: PartialEq> PartialEq<AvlTreeMap<K, V>> for AvlTreeMap<K, V>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: PartialOrd, V: PartialOrd> PartialOrd<AvlTreeMap<K, V>> for AvlTreeMap<K, V>

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K: Eq, V: Eq> Eq for AvlTreeMap<K, V>

source§

impl<K, V> Send for AvlTreeMap<K, V>where K: Send, V: Send,

source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.