Struct weak_table::WeakKeyHashMap
source · [−]pub struct WeakKeyHashMap<K, V, S = RandomState> { /* private fields */ }
Expand description
A hash map with weak keys, hashed on key value.
When a weak pointer expires, its mapping is lazily removed.
Implementations
sourceimpl<K: WeakKey, V> WeakKeyHashMap<K, V, RandomState>
impl<K: WeakKey, V> WeakKeyHashMap<K, V, RandomState>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty WeakKeyHashMap
with the given capacity.
O(n) time
sourceimpl<K: WeakKey, V, S: BuildHasher> WeakKeyHashMap<K, V, S>
impl<K: WeakKey, V, S: BuildHasher> WeakKeyHashMap<K, V, S>
sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates an empty WeakKeyHashMap
with the given capacity and hasher.
O(n) time
sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates an empty WeakKeyHashMap
with the given capacity and hasher.
O(n) time
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
O(1) time
sourcepub fn remove_expired(&mut self)
pub fn remove_expired(&mut self)
Removes all mappings whose keys have expired.
O(n) time
sourcepub fn reserve(&mut self, additional_capacity: usize)
pub fn reserve(&mut self, additional_capacity: usize)
Reserves room for additional elements.
O(n) time
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity to the minimum allowed to hold the current number of elements.
O(n) time
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Is the map empty?
Note that this may return false even if all keys in the map have expired, if they haven’t been collected yet.
O(1) time
sourcepub fn load_factor(&self) -> f32
pub fn load_factor(&self) -> f32
The proportion of buckets that are used.
This is an over-approximation because of expired keys.
O(1) time
sourcepub fn entry(&mut self, key: K::Strong) -> Entry<'_, K, V>
pub fn entry(&mut self, key: K::Strong) -> Entry<'_, K, V>
Gets the requested entry.
expected O(1) time; worst-case O(p) time
sourcepub fn get<Q>(&self, key: &Q) -> Option<&V> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn get<Q>(&self, key: &Q) -> Option<&V> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Returns a reference to the value corresponding to the key.
expected O(1) time; worst-case O(p) time
sourcepub fn contains_key<Q>(&self, key: &Q) -> bool where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn contains_key<Q>(&self, key: &Q) -> bool where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Returns true if the map contains the specified key.
expected O(1) time; worst-case O(p) time
sourcepub fn get_key<Q>(&self, key: &Q) -> Option<K::Strong> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn get_key<Q>(&self, key: &Q) -> Option<K::Strong> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Returns a strong reference to the key, if found.
expected O(1) time; worst-case O(p) time
sourcepub fn get_both<Q>(&self, key: &Q) -> Option<(K::Strong, &V)> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn get_both<Q>(&self, key: &Q) -> Option<(K::Strong, &V)> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Returns a pair of a strong reference to the key, and a reference to the value, if present.
expected O(1) time; worst-case O(p) time
sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Returns a mutable reference to the value corresponding to the key.
expected O(1) time; worst-case O(p) time
sourcepub fn get_both_mut<Q>(&mut self, key: &Q) -> Option<(K::Strong, &mut V)> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn get_both_mut<Q>(&mut self, key: &Q) -> Option<(K::Strong, &mut V)> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Returns a pair of a strong reference to the key, and a mutable reference to the value, if present.
expected O(1) time; worst-case O(p) time
sourcepub fn insert(&mut self, key: K::Strong, value: V) -> Option<V>
pub fn insert(&mut self, key: K::Strong, value: V) -> Option<V>
Unconditionally inserts the value, returning the old value if already present.
Unlike std::collections::HashMap
, this replaced the key even if occupied.
expected O(1) time; worst-case O(p) time
sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
pub fn remove<Q>(&mut self, key: &Q) -> Option<V> where
Q: ?Sized + Hash + Eq,
K::Key: Borrow<Q>,
Removes the entry with the given key, if it exists, and returns the value.
expected O(1) time; worst-case O(p) time
sourcepub fn retain<F>(&mut self, f: F) where
F: FnMut(K::Strong, &mut V) -> bool,
pub fn retain<F>(&mut self, f: F) where
F: FnMut(K::Strong, &mut V) -> bool,
Removes all mappings not satisfying the given predicate.
Also removes any expired mappings.
O(n) time
sourcepub fn is_submap_with<F, S1, V1>(
&self,
other: &WeakKeyHashMap<K, V1, S1>,
cmp: F
) -> bool where
F: FnMut(&V, &V1) -> bool,
S1: BuildHasher,
pub fn is_submap_with<F, S1, V1>(
&self,
other: &WeakKeyHashMap<K, V1, S1>,
cmp: F
) -> bool where
F: FnMut(&V, &V1) -> bool,
S1: BuildHasher,
Is this map a submap of the other under the given value comparison cmp
?
In particular, for every key k
of self
,
k
must also be a key ofother
andcmp(self[k], other[k])
must hold.
expected O(n) time; worst-case O(nq) time (where n is
self.capacity()
and q is the length of the probe sequences
in other
)
sourcepub fn is_submap<V1, S1>(&self, other: &WeakKeyHashMap<K, V1, S1>) -> bool where
V: PartialEq<V1>,
S1: BuildHasher,
pub fn is_submap<V1, S1>(&self, other: &WeakKeyHashMap<K, V1, S1>) -> bool where
V: PartialEq<V1>,
S1: BuildHasher,
Is self
a submap of other
?
expected O(n) time; worst-case O(nq) time (where n is
self.capacity()
and q is the length of the probe sequences
in other
)
sourcepub fn domain_is_subset<V1, S1>(
&self,
other: &WeakKeyHashMap<K, V1, S1>
) -> bool where
S1: BuildHasher,
pub fn domain_is_subset<V1, S1>(
&self,
other: &WeakKeyHashMap<K, V1, S1>
) -> bool where
S1: BuildHasher,
Are the keys of self
a subset of the keys of other
?
expected O(n) time; worst-case O(nq) time (where n is
self.capacity()
and q is the length of the probe sequences
in other
)
sourceimpl<K: WeakElement, V, S> WeakKeyHashMap<K, V, S>
impl<K: WeakElement, V, S> WeakKeyHashMap<K, V, S>
sourcepub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K: WeakElement, V> Iterator for Iter<'a, K, V> type Item = (K::Strong, &'a V);
pub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K: WeakElement, V> Iterator for Iter<'a, K, V> type Item = (K::Strong, &'a V);
Gets an iterator over the keys and values.
O(1) time
sourcepub fn keys(&self) -> Keys<'_, K, V>ⓘNotable traits for Keys<'a, K, V>impl<'a, K: WeakElement, V> Iterator for Keys<'a, K, V> type Item = K::Strong;
pub fn keys(&self) -> Keys<'_, K, V>ⓘNotable traits for Keys<'a, K, V>impl<'a, K: WeakElement, V> Iterator for Keys<'a, K, V> type Item = K::Strong;
Gets an iterator over the keys.
O(1) time
sourcepub fn values(&self) -> Values<'_, K, V>ⓘNotable traits for Values<'a, K, V>impl<'a, K: WeakElement, V> Iterator for Values<'a, K, V> type Item = &'a V;
pub fn values(&self) -> Values<'_, K, V>ⓘNotable traits for Values<'a, K, V>impl<'a, K: WeakElement, V> Iterator for Values<'a, K, V> type Item = &'a V;
Gets an iterator over the values.
O(1) time
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>ⓘNotable traits for IterMut<'a, K, V>impl<'a, K: WeakElement, V> Iterator for IterMut<'a, K, V> type Item = (K::Strong, &'a mut V);
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>ⓘNotable traits for IterMut<'a, K, V>impl<'a, K: WeakElement, V> Iterator for IterMut<'a, K, V> type Item = (K::Strong, &'a mut V);
Gets an iterator over the keys and mutable values.
O(1) time
sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>ⓘNotable traits for ValuesMut<'a, K, V>impl<'a, K: WeakElement, V> Iterator for ValuesMut<'a, K, V> type Item = &'a mut V;
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>ⓘNotable traits for ValuesMut<'a, K, V>impl<'a, K: WeakElement, V> Iterator for ValuesMut<'a, K, V> type Item = &'a mut V;
Gets an iterator over the mutable values.
O(1) time
Trait Implementations
sourceimpl<K: Clone, V: Clone, S: Clone> Clone for WeakKeyHashMap<K, V, S>
impl<K: Clone, V: Clone, S: Clone> Clone for WeakKeyHashMap<K, V, S>
sourcefn clone(&self) -> WeakKeyHashMap<K, V, S>
fn clone(&self) -> WeakKeyHashMap<K, V, S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<K: WeakElement, V: Debug, S> Debug for WeakKeyHashMap<K, V, S> where
K::Strong: Debug,
impl<K: WeakElement, V: Debug, S> Debug for WeakKeyHashMap<K, V, S> where
K::Strong: Debug,
sourceimpl<K: WeakKey, V, S: BuildHasher + Default> Default for WeakKeyHashMap<K, V, S>
impl<K: WeakKey, V, S: BuildHasher + Default> Default for WeakKeyHashMap<K, V, S>
sourceimpl<'a, K, V, S> Extend<(&'a <K as WeakElement>::Strong, &'a V)> for WeakKeyHashMap<K, V, S> where
K: 'a + WeakKey,
K::Strong: Clone,
V: 'a + Clone,
S: BuildHasher,
impl<'a, K, V, S> Extend<(&'a <K as WeakElement>::Strong, &'a V)> for WeakKeyHashMap<K, V, S> where
K: 'a + WeakKey,
K::Strong: Clone,
V: 'a + Clone,
S: BuildHasher,
sourcefn extend<T: IntoIterator<Item = (&'a K::Strong, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (&'a K::Strong, &'a V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K, V, S> Extend<(<K as WeakElement>::Strong, V)> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
S: BuildHasher,
impl<K, V, S> Extend<(<K as WeakElement>::Strong, V)> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
S: BuildHasher,
sourcefn extend<T: IntoIterator<Item = (K::Strong, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K::Strong, V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K, V, S> FromIterator<(<K as WeakElement>::Strong, V)> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
S: BuildHasher + Default,
impl<K, V, S> FromIterator<(<K as WeakElement>::Strong, V)> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
S: BuildHasher + Default,
sourceimpl<'a, K, V, S, Q> Index<&'a Q> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
K::Key: Borrow<Q>,
S: BuildHasher,
Q: ?Sized + Eq + Hash,
impl<'a, K, V, S, Q> Index<&'a Q> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
K::Key: Borrow<Q>,
S: BuildHasher,
Q: ?Sized + Eq + Hash,
sourceimpl<'a, K, V, S, Q> IndexMut<&'a Q> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
K::Key: Borrow<Q>,
S: BuildHasher,
Q: ?Sized + Eq + Hash,
impl<'a, K, V, S, Q> IndexMut<&'a Q> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
K::Key: Borrow<Q>,
S: BuildHasher,
Q: ?Sized + Eq + Hash,
sourceimpl<K: WeakElement, V, S> IntoIterator for WeakKeyHashMap<K, V, S>
impl<K: WeakElement, V, S> IntoIterator for WeakKeyHashMap<K, V, S>
sourceimpl<'a, K: WeakElement, V, S> IntoIterator for &'a WeakKeyHashMap<K, V, S>
impl<'a, K: WeakElement, V, S> IntoIterator for &'a WeakKeyHashMap<K, V, S>
sourceimpl<'a, K: WeakElement, V, S> IntoIterator for &'a mut WeakKeyHashMap<K, V, S>
impl<'a, K: WeakElement, V, S> IntoIterator for &'a mut WeakKeyHashMap<K, V, S>
sourceimpl<K, V, V1, S, S1> PartialEq<WeakKeyHashMap<K, V1, S1>> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
V: PartialEq<V1>,
S: BuildHasher,
S1: BuildHasher,
impl<K, V, V1, S, S1> PartialEq<WeakKeyHashMap<K, V1, S1>> for WeakKeyHashMap<K, V, S> where
K: WeakKey,
V: PartialEq<V1>,
S: BuildHasher,
S1: BuildHasher,
impl<K: WeakKey, V: Eq, S: BuildHasher> Eq for WeakKeyHashMap<K, V, S>
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for WeakKeyHashMap<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, S> Send for WeakKeyHashMap<K, V, S> where
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for WeakKeyHashMap<K, V, S> where
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> Unpin for WeakKeyHashMap<K, V, S> where
S: Unpin,
impl<K, V, S> UnwindSafe for WeakKeyHashMap<K, V, S> where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more