Struct TotalHashMap

Source
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>

Source

pub fn new() -> Self

Constructs a TotalHashMap in which all keys are associated with the common value.

Source§

impl<K, V, C> TotalHashMap<K, V, C>

Source

pub fn len(&self) -> usize

Returns the number of uncommon entries in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no uncommon entries.

Source

pub fn clear(&mut self)

Resets all entries in the map to the common value.

Source§

impl<K: Eq + Hash, V, C> TotalHashMap<K, V, C>

Source

pub fn get<Q>(&self, key: &Q) -> &V
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns a reference to the value associated with the given key.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns true if the map contains an uncommon entry with the given key.

Source§

impl<K: Eq + Hash, V, C: Commonality<V>> TotalHashMap<K, V, C>

Source

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.

Source

pub fn remove<Q>(&mut self, key: &Q) -> V
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Associates a key with the common value in the map, and returns the value previously associated with that key.

Source

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.

Source

pub fn uncommon_entry<'a, Q>( &'a mut self, key: &'a Q, ) -> Option<Entry<'a, Q, K, V, C>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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>

Source

pub fn keys(&self) -> Keys<'_, K, V>

An iterator over all keys associated with uncommon values in the map, in arbitrary order.

Source

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.

Source

pub fn values(&self) -> Values<'_, K, V>

An iterator over all uncommon values in the map, in arbitrary order.

Source

pub fn into_values(self) -> IntoValues<K, V>

Creates a consuming iterator over all uncommon values in the map, in arbitrary order.

Source

pub fn iter(&self) -> Iter<'_, K, V>

An iterator over all uncommon entries in the map, in arbitrary order.

Source

pub fn drain(&mut self) -> Drain<'_, K, V>

Resets all entries in the map to the common value, and returns all previously uncommon entries as an iterator.

Source§

impl<K, V, C> TotalHashMap<K, V, C>

Source

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>

Source

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: Clone, V: Clone, C> Clone for TotalHashMap<K, V, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V, C: Commonality<V>> Commonality<TotalHashMap<K, V, C>> for EmptyCommonality

Source§

fn common() -> TotalHashMap<K, V, C>

The common value of type V.
Source§

fn is_common(value: &TotalHashMap<K, V, C>) -> bool

Returns true if value is the common value of type V. Self::is_common(Self::common()) must be true.
Source§

impl<K: Debug, V: Debug, C> Debug for TotalHashMap<K, V, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, C: Commonality<V>> Default for TotalHashMap<K, V, C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

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)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: Eq + Hash, V, C: Commonality<V>> FromIterator<(K, V)> for TotalHashMap<K, V, C>

Source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Eq + Hash + Borrow<Q>, Q: Eq + Hash + ?Sized, V, C> Index<&Q> for TotalHashMap<K, V, C>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, K, V, C> IntoIterator for &'a TotalHashMap<K, V, C>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V, C> IntoIterator for TotalHashMap<K, V, C>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: Eq + Hash, V: PartialEq, C> PartialEq for TotalHashMap<K, V, C>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K: Serialize, V: Serialize, C> Serialize for TotalHashMap<K, V, C>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<K: Eq + Hash, V: Eq, C> Eq for TotalHashMap<K, V, C>

Auto Trait Implementations§

§

impl<K, V, C> Freeze for TotalHashMap<K, V, C>
where V: Freeze,

§

impl<K, V, C> RefUnwindSafe for TotalHashMap<K, V, C>

§

impl<K, V, C> Send for TotalHashMap<K, V, C>
where V: Send, K: Send,

§

impl<K, V, C> Sync for TotalHashMap<K, V, C>
where V: Sync, K: Sync,

§

impl<K, V, C> Unpin for TotalHashMap<K, V, C>
where V: Unpin, K: Unpin,

§

impl<K, V, C> UnwindSafe for TotalHashMap<K, V, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,