pub struct TotalHashMap<K, V, C = DefaultCommonality> { /* private fields */ }
Expand description
A hash map in which every possible key has an associated value. Only entries with uncommon values are actually stored in the map; all other keys are presumed to be associated with a common value.
See the crate documentation for more information.
The API more-or-less matches that of HashMap. However, methods that treat this type like a
collection (for example, len()
and iter()
) operate only on the
uncommon entries.
Implementations§
Source§impl<K, V, C: Commonality<V>> TotalHashMap<K, V, C>
impl<K, V, C: Commonality<V>> TotalHashMap<K, V, C>
Source§impl<K, V, C> TotalHashMap<K, V, C>
impl<K, V, C> TotalHashMap<K, V, C>
Source§impl<K: Eq + Hash, V, C> TotalHashMap<K, V, C>
impl<K: Eq + Hash, V, C> TotalHashMap<K, V, C>
Source§impl<K: Eq + Hash, V, C: Commonality<V>> TotalHashMap<K, V, C>
impl<K: Eq + Hash, V, C: Commonality<V>> TotalHashMap<K, V, C>
Sourcepub fn insert(&mut self, key: K, value: V) -> V
pub fn insert(&mut self, key: K, value: V) -> V
Associates a key with a value in the map, and returns the value previously associated with that key.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> V
pub fn remove<Q>(&mut self, key: &Q) -> V
Associates a key with the common value in the map, and returns the value previously associated with that key.
Sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, K, V, C>
pub fn entry(&mut self, key: K) -> Entry<'_, K, K, V, C>
Gets the given key’s associated entry in the map for in-place manipulation.
Sourcepub fn uncommon_entry<'a, Q>(
&'a mut self,
key: &'a Q,
) -> Option<Entry<'a, Q, K, V, C>>
pub fn uncommon_entry<'a, Q>( &'a mut self, key: &'a Q, ) -> Option<Entry<'a, Q, K, V, C>>
Gets the given key’s associated entry in the map if it has an uncommon value; otherwise returns None.
In contrast with Self::entry, this method accepts the key in borrowed form.
Source§impl<K, V, C> TotalHashMap<K, V, C>
impl<K, V, C> TotalHashMap<K, V, C>
Sourcepub fn keys(&self) -> Keys<'_, K, V> ⓘ
pub fn keys(&self) -> Keys<'_, K, V> ⓘ
An iterator over all keys associated with uncommon values in the map, in arbitrary order.
Sourcepub fn into_keys(self) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self) -> IntoKeys<K, V> ⓘ
Creates a consuming iterator over all keys associated with uncommon values in the map, in arbitrary order.
Sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
An iterator over all uncommon values in the map, in arbitrary order.
Sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
Creates a consuming iterator over all uncommon values in the map, in arbitrary order.
Source§impl<K, V, C> TotalHashMap<K, V, C>
impl<K, V, C> TotalHashMap<K, V, C>
Sourcepub fn as_hash_map(&self) -> &HashMap<K, V>
pub fn as_hash_map(&self) -> &HashMap<K, V>
Returns a view into the underlying HashMap of a TotalHashMap, which contains the uncommon entries.
Source§impl<K, V, C: Commonality<V>> TotalHashMap<K, V, C>
impl<K, V, C: Commonality<V>> TotalHashMap<K, V, C>
Sourcepub fn as_hash_map_mut(&mut self) -> AsHashMapMut<'_, K, V, C>
pub fn as_hash_map_mut(&mut self) -> AsHashMapMut<'_, K, V, C>
Returns a mutable view into the underlying HashMap of a TotalHashMap, from which mutating iterators can be obtained by calling HashMap::values_mut or HashMap::iter_mut.
By directly mutating the underlying HashMap, it is possible to store uncommon entries in the map temporarily. When the returned view is dropped, all uncommon entries will be removed, restoring the invariant of TotalHashMap.
You don’t need this method if you are only mutating individual entries; use the entry method instead.
Trait Implementations§
Source§impl<K, V, C: Commonality<V>> Commonality<TotalHashMap<K, V, C>> for EmptyCommonality
impl<K, V, C: Commonality<V>> Commonality<TotalHashMap<K, V, C>> for EmptyCommonality
Source§fn common() -> TotalHashMap<K, V, C>
fn common() -> TotalHashMap<K, V, C>
V
.Source§fn is_common(value: &TotalHashMap<K, V, C>) -> bool
fn is_common(value: &TotalHashMap<K, V, C>) -> bool
value
is the common value of type V
. Self::is_common(Self::common())
must be true.Source§impl<K, V, C: Commonality<V>> Default for TotalHashMap<K, V, C>
impl<K, V, C: Commonality<V>> Default for TotalHashMap<K, V, C>
Source§impl<'de, K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, C: Commonality<V>> Deserialize<'de> for TotalHashMap<K, V, C>
impl<'de, K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, C: Commonality<V>> Deserialize<'de> for TotalHashMap<K, V, C>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<K: Eq + Hash, V, C: Commonality<V>> Extend<(K, V)> for TotalHashMap<K, V, C>
impl<K: Eq + Hash, V, C: Commonality<V>> Extend<(K, V)> for TotalHashMap<K, V, C>
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
)