pub enum SsoHashMap<K, V> {
Array(ArrayVec<(K, V), 8>),
Map(HashMap<K, V, FxBuildHasher>),
}
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§
Implementations§
Source§impl<K, V> SsoHashMap<K, V>
impl<K, V> SsoHashMap<K, V>
Sourcepub fn new() -> SsoHashMap<K, V>
pub fn new() -> SsoHashMap<K, V>
Creates an empty SsoHashMap
.
Sourcepub fn with_capacity(cap: usize) -> SsoHashMap<K, V>
pub fn with_capacity(cap: usize) -> SsoHashMap<K, V>
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,
) -> Either<Map<Iter<'_, (K, V)>, fn(_: &(K, V)) -> (&K, &V)>, Iter<'_, K, V>>
pub fn iter( &self, ) -> Either<Map<Iter<'_, (K, V)>, fn(_: &(K, V)) -> (&K, &V)>, Iter<'_, K, V>>
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
.
Source§impl<K, V> SsoHashMap<K, V>
impl<K, V> SsoHashMap<K, V>
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 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§
Source§impl<K, V> Clone for SsoHashMap<K, V>
impl<K, V> Clone for SsoHashMap<K, V>
Source§fn clone(&self) -> SsoHashMap<K, V>
fn clone(&self) -> SsoHashMap<K, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<K, V> Debug for SsoHashMap<K, V>
impl<K, V> Debug for SsoHashMap<K, V>
Source§impl<K, V> Default for SsoHashMap<K, V>
impl<K, V> Default for SsoHashMap<K, V>
Source§fn default() -> SsoHashMap<K, V>
fn default() -> SsoHashMap<K, V>
Source§impl<'a, K, V> Extend<(&'a K, &'a V)> for SsoHashMap<K, V>
impl<'a, K, V> Extend<(&'a K, &'a V)> for SsoHashMap<K, V>
Source§fn extend<T>(&mut self, iter: T)
fn extend<T>(&mut self, iter: T)
Source§fn extend_one(&mut self, _: (&'a K, &'a V))
fn extend_one(&mut self, _: (&'a K, &'a V))
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<K, V> Extend<(K, V)> for SsoHashMap<K, V>
impl<K, V> Extend<(K, V)> for SsoHashMap<K, V>
Source§fn 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)>,
Source§fn extend_one(&mut self, _: (K, V))
fn extend_one(&mut self, _: (K, V))
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<K, V> FromIterator<(K, V)> for SsoHashMap<K, V>
impl<K, V> FromIterator<(K, V)> for SsoHashMap<K, V>
Source§fn from_iter<I>(iter: I) -> SsoHashMap<K, V>where
I: IntoIterator<Item = (K, V)>,
fn from_iter<I>(iter: I) -> SsoHashMap<K, V>where
I: IntoIterator<Item = (K, V)>,
Source§impl<'a, K, V> Index<&'a K> for SsoHashMap<K, V>
impl<'a, K, V> Index<&'a K> for SsoHashMap<K, V>
Source§impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V>
impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V>
Source§impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V>
Source§impl<K, V> IntoIterator for SsoHashMap<K, V>
impl<K, V> IntoIterator for SsoHashMap<K, V>
Auto Trait Implementations§
impl<K, V> DynSend for SsoHashMap<K, V>
impl<K, V> DynSync for SsoHashMap<K, V>
impl<K, V> Freeze for SsoHashMap<K, V>
impl<K, V> RefUnwindSafe for SsoHashMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SsoHashMap<K, V>
impl<K, V> Sync for SsoHashMap<K, V>
impl<K, V> Unpin for SsoHashMap<K, V>
impl<K, V> UnwindSafe for SsoHashMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync 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.