pub struct VecMap<K, V> { /* private fields */ }
Expand description
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§
Source§impl<K, V> VecMap<K, V>
impl<K, V> VecMap<K, V>
pub fn new() -> Selfwhere
K: PartialEq,
pub fn with_capacity(capacity: usize) -> Selfwhere
K: PartialEq,
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
pub fn clear(&mut self)
pub fn contains_key<Q: PartialEq<K> + ?Sized>(&self, key: &Q) -> bool
pub fn get<'l, Q: PartialEq<K> + ?Sized>(&'l self, key: &Q) -> Option<&'l V>
pub fn get_mut<'l, Q: PartialEq<K> + ?Sized>( &'l mut self, key: &Q, ) -> Option<&'l mut V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: PartialEq,
pub fn drain(&mut self) -> Drain<'_, K, V> ⓘ
pub fn reserve(&mut self, additional: usize)
pub fn shrink_to_fit(&mut self)
pub fn get_key_value<'l, Q: PartialEq<K> + ?Sized>( &'l self, key: &Q, ) -> Option<(&'l K, &'l V)>
pub fn remove<Q: PartialEq<K> + ?Sized>(&mut self, key: &Q) -> Option<V>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>where
K: PartialEq,
pub fn remove_entry<Q: PartialEq<K> + ?Sized>( &mut self, key: &Q, ) -> Option<(K, V)>
pub fn retain<F: FnMut(&K, &mut V) -> bool>(&mut self, f: F)
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn sort(&mut self)where
K: Ord,
Sourcepub unsafe fn identical(&self, other: &Self) -> bool
pub unsafe fn identical(&self, other: &Self) -> bool
Much faster than self == other
, but will return false if the order of the data isn’t identical.
§Safety
Note that for the order of data with two VecMap
s 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(&self) -> Keys<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
Trait Implementations§
Source§impl<'a, K: PartialEq + Copy + 'a, V: Copy + 'a> Extend<(&'a K, &'a V)> for VecMap<K, V>
impl<'a, K: PartialEq + Copy + 'a, V: Copy + 'a> Extend<(&'a K, &'a V)> for VecMap<K, V>
Source§fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, K: PartialEq, V> Extend<(K, V)> for VecMap<K, V>
impl<'a, K: PartialEq, V> Extend<(K, V)> for VecMap<K, V>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)