Skip to main content

DoubleMap

Struct DoubleMap 

Source
pub struct DoubleMap<K1, K2, V> { /* private fields */ }
Expand description

A map-like container supporting O(1) lookup by two key types.

Implementations§

Source§

impl<K1, K2, V> DoubleMap<K1, K2, V>

Source

pub fn new() -> Self

Constructs a new, empty DoubleMap.

Source

pub fn with_capacity(capacity: usize) -> Self

Constructs a new, empty DoubleMap with at least the specified capacity for both internal maps.

Source

pub fn capacity(&self) -> usize

Returns the minimum of the two internal capacities.

Source

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

Returns an iterator over the keys, yielding a (&K1, &K2) tuple for each entry.

Source

pub fn into_keys(self) -> IntoKeys<K1, K2, V>

Creates a consuming iterator yielding owned (K1, K2) key tuples in arbitrary order. The map cannot be used after calling this.

Source

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

Returns an iterator over the values.

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, K1, K2, V>

Returns an iterator yielding mutable references to each value.

Source

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

Creates a consuming iterator yielding owned values in arbitrary order. The map cannot be used after calling this.

Source

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

Returns an iterator yielding every entry as (&K1, &K2, &V).

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K1, K2, V>

Returns an iterator yielding every entry as (&K1, &K2, &mut V).

Neither key is mutably accessible — mutating them would desync the two internal maps.

Source

pub fn len(&self) -> usize

Returns the number of entries in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no entries.

Source

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

Clears the map, returning all entries as an iterator.

Source

pub fn clear(&mut self)

Removes all entries.

Source§

impl<K1, K2, V> DoubleMap<K1, K2, V>
where K1: Eq + Hash, K2: Eq + Hash,

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K1, &K2, &mut V) -> bool,

Retains only the entries for which the predicate returns true.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more entries in both internal maps.

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Tries to reserve capacity for at least additional more entries in both internal maps. Returns an error on allocation failure.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the internal maps to fit the current number of entries.

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the internal maps toward the given lower bound.

Source

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

Returns a reference to the value corresponding to the K1 key.

Source

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

Returns a reference to the value corresponding to the K2 key.

Source

pub fn get_by_keys<Q1, Q2>(&self, key1: &Q1, key2: &Q2) -> Option<&V>
where K1: Borrow<Q1>, K2: Borrow<Q2>, Q1: Eq + Hash + ?Sized, Q2: Eq + Hash + ?Sized,

Returns a reference to the value for the entry whose K1 key equals key1 and whose K2 key equals key2. Returns None if either key is missing, or if they refer to different entries.

Source

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

Returns the stored K1 key and value for the entry identified by the given K1 key.

Source

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

Returns the stored K2 key and value for the entry identified by the given K2 key.

Source

pub fn get_keys_value<Q1, Q2>( &self, key1: &Q1, key2: &Q2, ) -> Option<(&K1, &K2, &V)>
where K1: Borrow<Q1>, K2: Borrow<Q2>, Q1: Eq + Hash + ?Sized, Q2: Eq + Hash + ?Sized,

Returns the stored (K1, K2, V) triple for the entry whose K1 key equals key1 and whose K2 key equals key2. Returns None if either key is missing, or if they refer to different entries.

Source

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

Returns true if the map contains a value for the given K1 key.

Source

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

Returns true if the map contains a value for the given K2 key.

Source

pub fn contains_keys<Q1, Q2>(&self, key1: &Q1, key2: &Q2) -> bool
where K1: Borrow<Q1>, K2: Borrow<Q2>, Q1: Eq + Hash + ?Sized, Q2: Eq + Hash + ?Sized,

Returns true if the map contains an entry whose K1 key equals key1 and whose K2 key equals key2 (i.e. both keys refer to the same entry).

Source

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

Returns a mutable reference to the value corresponding to the K1 key.

Source

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

Returns a mutable reference to the value corresponding to the K2 key.

Source

pub fn get_mut_by_keys<Q1, Q2>( &mut self, key1: &Q1, key2: &Q2, ) -> Option<&mut V>
where K1: Borrow<Q1>, K2: Borrow<Q2>, Q1: Eq + Hash + ?Sized, Q2: Eq + Hash + ?Sized,

Returns a mutable reference to the value for the entry whose K1 key equals key1 and whose K2 key equals key2. Returns None if either key is missing, or if they refer to different entries.

Source

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

Removes an entry by its K1 key, returning the value if it was present.

Source

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

Removes an entry by its K2 key, returning the value if it was present.

Source

pub fn remove_by_keys<Q1, Q2>(&mut self, key1: &Q1, key2: &Q2) -> Option<V>
where K1: Borrow<Q1>, K2: Borrow<Q2>, Q1: Eq + Hash + ?Sized, Q2: Eq + Hash + ?Sized,

Removes an entry only if its K1 key equals key1 and its K2 key equals key2. Returns the value on success, or None if either key is missing or they refer to different entries. On mismatch, the map is unchanged.

Source

pub fn remove_entry_by_key1<Q>(&mut self, key: &Q) -> Option<(K1, K2, V)>
where K1: Borrow<Q>, Q: Eq + Hash + ?Sized,

Removes an entry by its K1 key, returning the full (K1, K2, V) triple if it was present.

Source

pub fn remove_entry_by_key2<Q>(&mut self, key: &Q) -> Option<(K1, K2, V)>
where K2: Borrow<Q>, Q: Eq + Hash + ?Sized,

Removes an entry by its K2 key, returning the full (K1, K2, V) triple if it was present.

Source

pub fn remove_entry_by_keys<Q1, Q2>( &mut self, key1: &Q1, key2: &Q2, ) -> Option<(K1, K2, V)>
where K1: Borrow<Q1>, K2: Borrow<Q2>, Q1: Eq + Hash + ?Sized, Q2: Eq + Hash + ?Sized,

Removes an entry only if its K1 key equals key1 and its K2 key equals key2. Returns the full (K1, K2, V) triple on success, or None if either key is missing or they refer to different entries. On mismatch, the map is unchanged.

Source§

impl<K1, K2, V> DoubleMap<K1, K2, V>
where K1: Eq + Hash + Clone, K2: Eq + Hash + Clone,

Source

pub fn entry( &mut self, key1: K1, key2: K2, ) -> Result<Entry<'_, K1, K2, V>, KeyConflictError<K1, K2>>

Gets the given (key1, key2) pair’s Entry in the map for in-place manipulation.

  • Returns Ok(Entry::Occupied) if both keys refer to the same existing entry.
  • Returns Ok(Entry::Vacant) if neither key is present.
  • Returns Err(KeyConflictError) if the two keys clash with existing entries. In the error case the map is unchanged and the rejected (K1, K2) pair is returned.
Source

pub fn insert( &mut self, key1: K1, key2: K2, value: V, ) -> Result<Option<V>, KeyConflictError<K1, K2, V>>

Inserts a new entry, or updates the value if both keys are already present and refer to the same entry.

  • Returns Ok(None) when neither key was present and a fresh entry was inserted.
  • Returns Ok(Some(old_value)) when both keys matched the same existing entry and its value was replaced.
  • Returns Err(KeyConflictError) if the two keys clash with existing entries. In all error cases the map is unchanged and the rejected triple is returned.

Trait Implementations§

Source§

impl<K1, K2, V> Clone for DoubleMap<K1, K2, V>
where K1: Clone, K2: Clone, V: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K1, K2, V> Debug for DoubleMap<K1, K2, V>
where K1: Debug, K2: Debug, V: Debug,

Source§

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

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

impl<K1, K2, V> Default for DoubleMap<K1, K2, V>

Source§

fn default() -> Self

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

impl<K1, K2, V> Eq for DoubleMap<K1, K2, V>
where K1: Eq + Hash, K2: Eq + Hash, V: Eq,

Source§

impl<'a, K1, K2, V> Extend<(&'a K1, &'a K2, &'a V)> for DoubleMap<K1, K2, V>
where K1: Eq + Hash + Copy, K2: Eq + Hash + Copy, V: Copy,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (&'a K1, &'a K2, &'a V)>,

Extends the map with borrowed (&K1, &K2, &V) triples, copying each element into place.

Conflicting triples are silently skipped, same as the owned-triple Extend impl.

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<K1, K2, V> Extend<(K1, K2, V)> for DoubleMap<K1, K2, V>
where K1: Eq + Hash + Clone, K2: Eq + Hash + Clone,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (K1, K2, V)>,

Extends the map with (K1, K2, V) triples from any iterator.

Triples whose keys conflict with an existing entry (same K1 mapped to a different K2, or same K2 mapped to a different K1) are silently skipped and the map is left unchanged for that triple. A consistent repeat (same K1 and same K2) updates the value.

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<K1, K2, V, const N: usize> From<[(K1, K2, V); N]> for DoubleMap<K1, K2, V>
where K1: Eq + Hash + Clone, K2: Eq + Hash + Clone,

Source§

fn from(arr: [(K1, K2, V); N]) -> Self

Builds a DoubleMap from an array of (K1, K2, V) triples.

Conflicting triples are silently skipped, same as FromIterator.

Source§

impl<K1, K2, V> FromIterator<(K1, K2, V)> for DoubleMap<K1, K2, V>
where K1: Eq + Hash + Clone, K2: Eq + Hash + Clone,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = (K1, K2, V)>,

Collects (K1, K2, V) triples into a fresh DoubleMap.

Conflicting triples are silently skipped, same as Extend.

Source§

impl<K1, K2, V, Q> Index<&Q> for DoubleMap<K1, K2, V>
where K1: Eq + Hash + Borrow<Q>, K2: Eq + Hash, Q: Eq + Hash + ?Sized,

Source§

fn index(&self, key: &Q) -> &V

Returns a reference to the value corresponding to the supplied key1.

§Panics

Panics if the key is not present in the map.

Source§

type Output = V

The returned type after indexing.
Source§

impl<K1, K2, V> IntoIterator for DoubleMap<K1, K2, V>

Source§

fn into_iter(self) -> Self::IntoIter

Consumes the map, yielding owned (K1, K2, V) triples.

Source§

type Item = (K1, K2, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K1, K2, V>

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

impl<'a, K1, K2, V> IntoIterator for &'a DoubleMap<K1, K2, V>

Source§

fn into_iter(self) -> Self::IntoIter

Borrows the map, yielding (&K1, &K2, &V) triples.

Source§

type Item = (&'a K1, &'a K2, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K1, K2, V>

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

impl<'a, K1, K2, V> IntoIterator for &'a mut DoubleMap<K1, K2, V>

Source§

fn into_iter(self) -> Self::IntoIter

Mutably borrows the map, yielding (&K1, &K2, &mut V) triples. Keys are exposed immutably to preserve the invariant that both internal maps stay in sync.

Source§

type Item = (&'a K1, &'a K2, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K1, K2, V>

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

impl<K1, K2, V> PartialEq for DoubleMap<K1, K2, V>
where K1: Eq + Hash, K2: Eq + Hash, V: PartialEq,

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<K1, K2, V> Freeze for DoubleMap<K1, K2, V>

§

impl<K1, K2, V> RefUnwindSafe for DoubleMap<K1, K2, V>

§

impl<K1, K2, V> Send for DoubleMap<K1, K2, V>
where K1: Send, K2: Send, V: Send,

§

impl<K1, K2, V> Sync for DoubleMap<K1, K2, V>
where K1: Sync, K2: Sync, V: Sync,

§

impl<K1, K2, V> Unpin for DoubleMap<K1, K2, V>
where K1: Unpin, K2: Unpin, V: Unpin,

§

impl<K1, K2, V> UnsafeUnpin for DoubleMap<K1, K2, V>

§

impl<K1, K2, V> UnwindSafe for DoubleMap<K1, K2, V>
where K1: UnwindSafe, K2: UnwindSafe, V: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more