[][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 unsafe fn inner(&self) -> &Vec<(K, V)>[src]

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

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

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

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

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

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

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

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

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]