pub struct FzHashMap<K, V, BH = RandomState> { /* private fields */ }Expand description
A map optimized for fast read access with hashable keys.
A frozen collection differs from the traditional Rust collections, such as
HashMap and HashSet types in three
key ways. First, creating a frozen collection performs an analysis over the input data to
determine the best implementation strategy. Depending on the situation, this analysis is
performed at build time or runtime, and it can take a relatively long time when a collection is
very large. Second, once created, the keys in frozen collections are immutable. And third,
querying a frozen collection is typically considerably faster, which is the whole point.
This type requires that the keys
implement the Eq and Hash traits. This can frequently be achieved by
using #[derive(PartialEq, Eq, Hash)]. If you implement these yourself,
it is important that the following property holds:
k1 == k2 -> hash(k1) == hash(k2)In other words, if two keys are equal, their hashes must be equal. Violating this property is a logic error.
It is also a logic error for a key to be modified in such a way that the key’s
hash, as determined by the Hash trait, or its equality, as determined by
the Eq trait, changes while it is in the collection. This is normally only
possible through core::cell::Cell, core::cell::RefCell, global state, I/O,
or unsafe code.
The behavior resulting from either logic error can include panics, incorrect results, memory leaks, and non-termination.
§Alternate Choices
If your keys are integers or enum variants, you should use the FzScalarMap type instead.
If your keys are strings, you should use the FzStringMap type instead. Both of these will
deliver better performance since they are specifically optimized for those key types.
If your keys are known at compile time, consider using the various fz_*_map macros instead of
this type as they generally perform better.
Implementations§
Source§impl<K, V, BH> FzHashMap<K, V, BH>where
BH: BuildHasher,
impl<K, V, BH> FzHashMap<K, V, BH>where
BH: BuildHasher,
Sourcepub fn with_hasher(entries: Vec<(K, V)>, bh: BH) -> FzHashMap<K, V, BH>
pub fn with_hasher(entries: Vec<(K, V)>, bh: BH) -> FzHashMap<K, V, BH>
Creates a frozen map which uses the given hash builder to hash keys. If the input contains duplicate keys, the latter one in the input is used and all former ones are discarded.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
This is potentially useful:
-
for key types where non-identical keys can be considered equal;
-
for getting the &K stored key value from a borrowed &Q lookup key; or
-
for getting a reference to a key with the same lifetime as the collection.
-
The supplied key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type.
Sourcepub fn get_disjoint_mut<Q, const N: usize>(
&mut self,
keys: [&Q; N],
) -> [Option<&mut V>; N]
pub fn get_disjoint_mut<Q, const N: usize>( &mut self, keys: [&Q; N], ) -> [Option<&mut V>; N]
Gets multiple mutable values from the map.
§Panics
Panics if the same key is specified multiple times.
Sourcepub unsafe fn get_disjoint_unchecked_mut<Q, const N: usize>(
&mut self,
keys: [&Q; N],
) -> [Option<&mut V>; N]
pub unsafe fn get_disjoint_unchecked_mut<Q, const N: usize>( &mut self, keys: [&Q; N], ) -> [Option<&mut V>; N]
Gets multiple mutable values from the map.
§Safety
Calling this method with overlapping keys is undefined behavior even if the resulting references are not used.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
An iterator producing mutable references to all entries in arbitrary order.
Sourcepub fn into_keys(self) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self) -> IntoKeys<K, V> ⓘ
A consuming iterator visiting all keys in arbitrary order.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
An iterator visiting all values mutably in arbitrary order.
Sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
A consuming iterator visiting all values in arbitrary order.
Trait Implementations§
Source§impl<'de, K, V, BH> Deserialize<'de> for FzHashMap<K, V, BH>
Available on crate feature serde only.
impl<'de, K, V, BH> Deserialize<'de> for FzHashMap<K, V, BH>
serde only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<FzHashMap<K, V, BH>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<FzHashMap<K, V, BH>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<K, V, BH> FromIterator<(K, V)> for FzHashMap<K, V, BH>
impl<K, V, BH> FromIterator<(K, V)> for FzHashMap<K, V, BH>
Source§impl<'a, K, V, BH> IntoIterator for &'a FzHashMap<K, V, BH>where
BH: BuildHasher,
impl<'a, K, V, BH> IntoIterator for &'a FzHashMap<K, V, BH>where
BH: BuildHasher,
Source§impl<'a, K, V, BH> IntoIterator for &'a mut FzHashMap<K, V, BH>where
BH: BuildHasher,
impl<'a, K, V, BH> IntoIterator for &'a mut FzHashMap<K, V, BH>where
BH: BuildHasher,
Source§impl<K, V, BH> IntoIterator for FzHashMap<K, V, BH>where
BH: BuildHasher,
impl<K, V, BH> IntoIterator for FzHashMap<K, V, BH>where
BH: BuildHasher,
Source§impl<K, V, BH> Len for FzHashMap<K, V, BH>where
BH: BuildHasher,
impl<K, V, BH> Len for FzHashMap<K, V, BH>where
BH: BuildHasher,
Source§impl<K, V, Q, BH> MapExtras<K, V, Q> for FzHashMap<K, V, BH>
impl<K, V, Q, BH> MapExtras<K, V, Q> for FzHashMap<K, V, BH>
Source§impl<K, V, BH> MapIteration<K, V> for FzHashMap<K, V, BH>where
BH: BuildHasher,
impl<K, V, BH> MapIteration<K, V> for FzHashMap<K, V, BH>where
BH: BuildHasher,
Source§type Iterator<'a> = Iter<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type Iterator<'a> = Iter<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::iter.Source§type KeyIterator<'a> = Keys<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type KeyIterator<'a> = Keys<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::keys.Source§type ValueIterator<'a> = Values<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type ValueIterator<'a> = Values<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::values.Source§type MutIterator<'a> = IterMut<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type MutIterator<'a> = IterMut<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::iter_mut.Source§type ValueMutIterator<'a> = ValuesMut<'a, K, V>
where
K: 'a,
V: 'a,
BH: 'a
type ValueMutIterator<'a> = ValuesMut<'a, K, V> where K: 'a, V: 'a, BH: 'a
Self::values_mut.Source§type IntoKeyIterator = IntoKeys<K, V>
type IntoKeyIterator = IntoKeys<K, V>
Self::into_keys.Source§type IntoValueIterator = IntoValues<K, V>
type IntoValueIterator = IntoValues<K, V>
Self::into_values.Source§fn iter(&self) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::Iterator<'_>
fn iter(&self) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::Iterator<'_>
Source§fn iter_mut(
&mut self,
) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::MutIterator<'_>
fn iter_mut( &mut self, ) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::MutIterator<'_>
Source§fn keys(&self) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::KeyIterator<'_>
fn keys(&self) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::KeyIterator<'_>
Source§fn into_keys(
self,
) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::IntoKeyIterator
fn into_keys( self, ) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::IntoKeyIterator
Source§fn values(
&self,
) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::ValueIterator<'_>
fn values( &self, ) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::ValueIterator<'_>
Source§fn values_mut(
&mut self,
) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::ValueMutIterator<'_>
fn values_mut( &mut self, ) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::ValueMutIterator<'_>
Source§fn into_values(
self,
) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::IntoValueIterator
fn into_values( self, ) -> <FzHashMap<K, V, BH> as MapIteration<K, V>>::IntoValueIterator
Source§impl<K, V, Q, BH> MapQuery<Q, V> for FzHashMap<K, V, BH>
impl<K, V, Q, BH> MapQuery<Q, V> for FzHashMap<K, V, BH>
Source§impl<K, V, BH> Serialize for FzHashMap<K, V, BH>
Available on crate feature serde only.
impl<K, V, BH> Serialize for FzHashMap<K, V, BH>
serde only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl<K, V, BH> Eq for FzHashMap<K, V, BH>
impl<K, V, Q, BH> Map<K, V, Q> for FzHashMap<K, V, BH>
Auto Trait Implementations§
impl<K, V, BH> Freeze for FzHashMap<K, V, BH>where
BH: Freeze,
impl<K, V, BH> RefUnwindSafe for FzHashMap<K, V, BH>
impl<K, V, BH> Send for FzHashMap<K, V, BH>
impl<K, V, BH> Sync for FzHashMap<K, V, BH>
impl<K, V, BH> Unpin for FzHashMap<K, V, BH>where
BH: Unpin,
impl<K, V, BH> UnsafeUnpin for FzHashMap<K, V, BH>where
BH: UnsafeUnpin,
impl<K, V, BH> UnwindSafe for FzHashMap<K, V, BH>
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.