Enum rustc_data_structures::sso::SsoHashMap
source · Expand description
Small-storage-optimized implementation of a map.
Stores elements in a small array up to a certain length
and switches to HashMap
when that length is exceeded.
Variants
Array(ArrayVec<(K, V), SSO_ARRAY_SIZE>)
Map(FxHashMap<K, V>)
Implementations
sourceimpl<K, V> SsoHashMap<K, V>
impl<K, V> SsoHashMap<K, V>
sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates an empty SsoHashMap
with the specified capacity.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
sourcepub fn iter(
&self
) -> EitherIter<Map<Iter<'_, (K, V)>, fn(&(K, V)) -> (&K, &V)>, Iter<'_, K, V>>ⓘNotable traits for EitherIter<L, R>impl<L, R> Iterator for EitherIter<L, R>where
L: Iterator,
R: Iterator<Item = L::Item>, type Item = L::Item;
pub fn iter(
&self
) -> EitherIter<Map<Iter<'_, (K, V)>, fn(&(K, V)) -> (&K, &V)>, Iter<'_, K, V>>ⓘNotable traits for EitherIter<L, R>impl<L, R> Iterator for EitherIter<L, R>where
L: Iterator,
R: Iterator<Item = L::Item>, type Item = L::Item;
L: Iterator,
R: Iterator<Item = L::Item>, type Item = L::Item;
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V)
.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
An iterator visiting all key-value pairs in arbitrary order,
with mutable references to the values.
The iterator element type is (&'a K, &'a mut V)
.
sourcepub fn keys(&self) -> impl Iterator<Item = &K>
pub fn keys(&self) -> impl Iterator<Item = &K>
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K
.
sourcepub fn values(&self) -> impl Iterator<Item = &V>
pub fn values(&self) -> impl Iterator<Item = &V>
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V
.
sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
An iterator visiting all values mutably in arbitrary order.
The iterator element type is &'a mut V
.
sourceimpl<K: Eq + Hash, V> SsoHashMap<K, V>
impl<K: Eq + Hash, V> SsoHashMap<K, V>
sourcefn migrate_if_full(&mut self)
fn migrate_if_full(&mut self)
Changes underlying storage from array to hashmap if array is full.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted
in the SsoHashMap
. The collection may reserve more space to avoid
frequent reallocations.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
sourcepub fn retain<F>(&mut self, f: F)where
F: FnMut(&K, &mut V) -> bool,
pub fn retain<F>(&mut self, f: F)where
F: FnMut(&K, &mut V) -> bool,
Retains only the elements specified by the predicate.
sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old
value is returned. The key is not updated, though; this matters for
types that can be ==
without being identical. See the [module-level
documentation] for more.
sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Removes a key from the map, returning the value at the key if the key was previously in the map.
sourcepub fn remove_entry(&mut self, key: &K) -> Option<(K, V)>
pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the key was previously in the map.
sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the key.
sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
sourcepub fn get_key_value(&self, key: &K) -> Option<(&K, &V)>
pub fn get_key_value(&self, key: &K) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true
if the map contains a value for the specified key.
Trait Implementations
sourceimpl<K: Clone, V: Clone> Clone for SsoHashMap<K, V>
impl<K: Clone, V: Clone> Clone for SsoHashMap<K, V>
sourcefn clone(&self) -> SsoHashMap<K, V>
fn clone(&self) -> SsoHashMap<K, V>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<K, V> Debug for SsoHashMap<K, V>where
K: Debug,
V: Debug,
impl<K, V> Debug for SsoHashMap<K, V>where
K: Debug,
V: Debug,
sourceimpl<K, V> Default for SsoHashMap<K, V>
impl<K, V> Default for SsoHashMap<K, V>
sourceimpl<'a, K, V> Extend<(&'a K, &'a V)> for SsoHashMap<K, V>where
K: Eq + Hash + Copy,
V: Copy,
impl<'a, K, V> Extend<(&'a K, &'a V)> for SsoHashMap<K, V>where
K: Eq + Hash + Copy,
V: Copy,
sourcefn 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)
sourcefn extend_one(&mut self, (k, v): (&'a K, &'a V))
fn extend_one(&mut self, (k, v): (&'a K, &'a V))
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<K: Eq + Hash, V> Extend<(K, V)> for SsoHashMap<K, V>
impl<K: Eq + Hash, V> Extend<(K, V)> for SsoHashMap<K, V>
sourcefn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
sourcefn extend_one(&mut self, (k, v): (K, V))
fn extend_one(&mut self, (k, v): (K, V))
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<K: Eq + Hash, V> FromIterator<(K, V)> for SsoHashMap<K, V>
impl<K: Eq + Hash, V> FromIterator<(K, V)> for SsoHashMap<K, V>
sourcefn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> SsoHashMap<K, V>
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> SsoHashMap<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V>
impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V>
sourceimpl<K, V> IntoIterator for SsoHashMap<K, V>
impl<K, V> IntoIterator for SsoHashMap<K, V>
Auto Trait Implementations
impl<K, V> RefUnwindSafe for SsoHashMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SsoHashMap<K, V>where
K: Send,
V: Send,
impl<K, V> Sync for SsoHashMap<K, V>where
K: Sync,
V: Sync,
impl<K, V> Unpin for SsoHashMap<K, V>where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for SsoHashMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> Erased for T
Layout
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.