[][src]Struct vector_map::VecMap

pub struct VecMap<K, V> { /* fields omitted */ }

A std::vec::Vec based Map, motivated by the fact that, for some key types, iterating over a vector can be faster than other methods for small maps.

Most of the operations on this map implementation work in O(n), including some of the ones that are O(1) in HashMap. However, optimizers can work magic with contiguous arrays like Vec, and so for small sets (up to 256 elements for integer keys, for example), iterating through a vector actually yields better performance than the less branch- and cache-predictable hash maps.

To keep item removal fast, this container doesn't form guaranties on item ordering, nor on the stability of the ordering.

The good news about that is that you're free to mutate keys if your use-case requires that, though I wouldn't recommend it: the underlying vector can be accessed through the unsafe part of the API, in hopes to discourage you from using it.

Checking equality between maps is defined as "both maps are the same set", and performs worst for maps that are permutations of each other.

Implementations

impl<K, V> VecMap<K, V>[src]

pub fn new() -> Self where
    K: PartialEq
[src]

Contracts

Post-condition: ret . len() == 0

pub fn with_capacity(capacity: usize) -> Self where
    K: PartialEq
[src]

Contracts

Post-condition: ret . len() == 0

pub fn len(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

pub fn capacity(&self) -> usize[src]

pub fn clear(&mut self)[src]

pub fn contains_key<Q: PartialEq<K>>(&self, key: &Q) -> bool[src]

pub fn get<'l, Q: PartialEq<K>>(&'l self, key: &Q) -> Option<&'l V>[src]

Contracts

Post-condition: ! self . contains_key(key) -> ret . is_none()

Post-condition: self . contains_key(key) -> ret . is_some()

pub fn get_mut<'l, Q: PartialEq<K>>(&'l mut self, key: &Q) -> Option<&'l mut V>[src]

Contracts

Post-condition: ! old(self . contains_key(key)) -> ret . is_none()

Post-condition: old(self . contains_key(key)) -> ret . is_some()

pub fn insert(&mut self, key: K, value: V) -> Option<V> where
    K: PartialEq
[src]

Contracts

Post-condition: ! old(self . contains_key(& key)) -> ret . is_none()

Post-condition: old(self . contains_key(& key)) -> ret . is_some()

pub fn drain<'l>(&'l mut self) -> Drain<'l, K, V>[src]

pub fn reserve(&mut self, additional: usize)[src]

pub fn shrink_to_fit(&mut self)[src]

pub fn get_key_value<'l, Q: PartialEq<K>>(
    &'l self,
    key: &Q
) -> Option<(&'l K, &'l V)>
[src]

Contracts

Post-condition: ! self . contains_key(key) -> ret . is_none()

Post-condition: self . contains_key(key) -> ret . is_some()

pub fn remove<Q: PartialEq<K>>(&mut self, key: &Q) -> Option<V>[src]

Contracts

Post-condition: ! old(self . contains_key(key)) -> ret . is_none()

Post-condition: old(self . contains_key(key)) -> ret . is_some()

Post-condition: self . contains_key(key) == false

pub fn remove_entry<Q: PartialEq<K>>(&mut self, key: &Q) -> Option<(K, V)>[src]

Contracts

Post-condition: ! old(self . contains_key(key)) -> ret . is_none()

Post-condition: old(self . contains_key(key)) -> ret . is_some()

Post-condition: self . contains_key(key) == false

pub fn retain<F: FnMut(&K, &mut V) -> bool>(&mut self, f: F)[src]

pub fn iter<'a>(&'a self) -> Iter<'a, K, V>[src]

pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, K, V>[src]

pub fn sort(&mut self) where
    K: Ord
[src]

pub unsafe fn identical(&self, other: &Self) -> bool where
    K: PartialEq,
    V: PartialEq
[src]

Much faster than self == other, but will return false if the order of the data isn't identical. Note that for the order of data with two VecMaps to be identical, they must either have been both sorted, or they must have undergone the insertion and removal of keys in the same order.

pub fn keys<'a>(&'a self) -> Keys<'a, K, V>[src]

pub fn values<'a>(&'a self) -> Values<'a, K, V>[src]

Trait Implementations

impl<K: Clone, V: Clone> Clone for VecMap<K, V>[src]

impl<K: Debug, V: Debug> Debug for VecMap<K, V>[src]

impl<K: Default, V: Default> Default for VecMap<K, V>[src]

impl<'a, K: PartialEq + Copy + 'a, V: Copy + 'a> Extend<(&'a K, &'a V)> for VecMap<K, V>[src]

impl<'a, K: PartialEq, V> Extend<(K, V)> for VecMap<K, V>[src]

impl<K: PartialEq, V> FromIterator<(K, V)> for VecMap<K, V>[src]

impl<'a, Q: PartialEq<K>, K, V> Index<&'a Q> for VecMap<K, V>[src]

type Output = V

The returned type after indexing.

impl<'a, Q: PartialEq<K>, K, V> IndexMut<&'a Q> for VecMap<K, V>[src]

impl<'a, K, V> IntoIterator for &'a VecMap<K, V>[src]

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?

impl<'a, K, V> IntoIterator for &'a mut VecMap<K, V>[src]

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?

impl<K, V> IntoIterator for VecMap<K, V>[src]

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?

impl<K: PartialEq, V: PartialEq> PartialEq<VecMap<K, V>> for VecMap<K, V>[src]

Auto Trait Implementations

impl<K, V> RefUnwindSafe for VecMap<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe

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

impl<K, V> Sync for VecMap<K, V> where
    K: Sync,
    V: Sync

impl<K, V> Unpin for VecMap<K, V> where
    K: Unpin,
    V: Unpin

impl<K, V> UnwindSafe for VecMap<K, V> where
    K: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,