[][src]Struct vector_map::VecMap

pub struct VecMap<K: PartialEq, 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.

Methods

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

pub fn new() -> Self[src]

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

pub fn inner(&self) -> &Vec<(K, V)>[src]

Returns a reference to the underlying vector, since the reference is immutable, you should be fine.

pub unsafe fn inner_mut(&mut self) -> &mut Vec<(K, V)>[src]

Returns a mutable reference to the underlying vector. Marked unsafe because you might break assertions such as key unicity if you're not careful.

pub unsafe fn push_insert(&mut self, key: K, value: V)[src]

Pushes the (key, value) tuple at the end of the map. Marked unsafe because you might break key unicity if you're not careful.

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

If the key was already in use, replace its associated value by the new one and return Some(old_value), otherwise, add the (key, value) tuple to the items. Capacity extension may invalidate aliases to elements of self.

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

Returns a reference to the value associated to key if it exists.

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

Returns a mutable reference to the value associated to key if it exists.

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

Removes a (key, value) tuple from the map and returns the associated value if it existed. This invalidates aliases to the target (key, value) pair as well as to the last (key, value) pair in the map.

pub fn keys<'l>(&'l self) -> Box<dyn Iterator<Item = &'l K> + 'l>[src]

Returns an iterator over the references to the keys in the map.

pub fn iter<'l>(&'l self) -> Box<dyn Iterator<Item = (&'l K, &'l V)> + 'l>[src]

Returns a map-like iterator over the key-value pairs.

pub fn iter_mut<'l>(
    &'l mut self
) -> Box<dyn Iterator<Item = (&'l K, &'l mut V)> + 'l>
[src]

Returns a map-like iterator over the key-value pairs with the reference to value being mutable.

Trait Implementations

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

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

impl<K: PartialEq, 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<'l, K: PartialEq, V> IntoIterator for &'l VecMap<K, V>[src]

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

The type of the elements being iterated over.

type IntoIter = Box<dyn Iterator<Item = (&'l K, &'l V)> + 'l>

Which kind of iterator are we turning this into?

impl<'l, K: PartialEq, V> IntoIterator for &'l mut VecMap<K, V>[src]

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

The type of the elements being iterated over.

type IntoIter = Box<dyn Iterator<Item = (&'l K, &'l mut V)> + 'l>

Which kind of iterator are we turning this into?

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

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

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

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

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

Auto Trait Implementations

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

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

Blanket Implementations

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

impl<T> From<T> for 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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

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