Struct weak_table::PtrWeakKeyHashMap [−][src]
pub struct PtrWeakKeyHashMap<K, V, S = RandomState>(_);
Expand description
A hash map with weak keys, hashed on key pointer.
When a weak pointer expires, its mapping is lazily removed.
Examples
use weak_table::PtrWeakKeyHashMap;
use std::rc::{Rc, Weak};
type Table = PtrWeakKeyHashMap<Weak<str>, usize>;
let mut map = Table::new();
let a = Rc::<str>::from("hello");
let b = Rc::<str>::from("hello");
map.insert(a.clone(), 5);
assert_eq!( map.get(&a), Some(&5) );
assert_eq!( map.get(&b), None );
map.insert(b.clone(), 7);
assert_eq!( map.get(&a), Some(&5) );
assert_eq!( map.get(&b), Some(&7) );
Implementations
Creates an empty PtrWeakKeyHashMap
with the given capacity.
Creates an empty PtrWeakKeyHashMap
with the given capacity and hasher.
Creates an empty PtrWeakKeyHashMap
with the given capacity and hasher.
Returns the number of elements the map can hold without reallocating.
Removes all mappings whose keys have expired.
Shrinks the capacity to the minimum allowed to hold the current number of elements.
Is the map known to be empty?
This could answer false
for an empty map whose keys have
expired but have yet to be collected.
The proportion of buckets that are used.
This is an over-approximation because of expired keys.
Returns a reference to the value corresponding to the key.
Returns true if the map contains the specified key.
Returns a mutable reference to the value corresponding to the key.
Unconditionally inserts the value, returning the old value if already present. Does not replace the key.
Removes the entry with the given key, if it exists, and returns the value.
Removes all mappings not satisfying the given predicate.
Also removes any expired mappings.
pub fn submap_with<F, S1, V1>(
&self,
other: &PtrWeakKeyHashMap<K, V1, S1>,
value_equal: F
) -> bool where
F: FnMut(&V, &V1) -> bool,
S1: BuildHasher,
pub fn submap_with<F, S1, V1>(
&self,
other: &PtrWeakKeyHashMap<K, V1, S1>,
value_equal: F
) -> bool where
F: FnMut(&V, &V1) -> bool,
S1: BuildHasher,
Is this map a submap of the other, using the given value comparison.
In particular, all the keys of self must be in other and the values must compare true with value_equal.
pub fn is_submap<V1, S1>(&self, other: &PtrWeakKeyHashMap<K, V1, S1>) -> bool where
V: PartialEq<V1>,
S1: BuildHasher,
pub fn is_submap<V1, S1>(&self, other: &PtrWeakKeyHashMap<K, V1, S1>) -> bool where
V: PartialEq<V1>,
S1: BuildHasher,
Is self a submap of other?
pub fn domain_is_subset<V1, S1>(
&self,
other: &PtrWeakKeyHashMap<K, V1, S1>
) -> bool where
S1: BuildHasher,
pub fn domain_is_subset<V1, S1>(
&self,
other: &PtrWeakKeyHashMap<K, V1, S1>
) -> bool where
S1: BuildHasher,
Are the keys of self a subset of the keys of other?
Gets an iterator over the keys and values.
Gets an iterator over the keys.
Gets an iterator over the values.
Gets an iterator over the keys and mutable values.
pub fn values_mut(&mut self) -> ValuesMut<'_, ByPtr<K>, V>ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, ByPtr<K>, V>ⓘ
Gets an iterator over the mutable values.
Trait Implementations
impl<K, V: Debug, S> Debug for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Debug,
impl<K, V: Debug, S> Debug for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Debug,
impl<K: WeakElement, V, S: BuildHasher + Default> Default for PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
impl<K: WeakElement, V, S: BuildHasher + Default> Default for PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
impl<'a, K, V, S> Extend<(&'a <K as WeakElement>::Strong, &'a V)> for PtrWeakKeyHashMap<K, V, S> where
K: 'a + WeakElement,
K::Strong: Clone + Deref,
V: 'a + Clone,
S: BuildHasher,
impl<'a, K, V, S> Extend<(&'a <K as WeakElement>::Strong, &'a V)> for PtrWeakKeyHashMap<K, V, S> where
K: 'a + WeakElement,
K::Strong: Clone + Deref,
V: 'a + Clone,
S: BuildHasher,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl<K, V, S> Extend<(<K as WeakElement>::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
impl<K, V, S> Extend<(<K as WeakElement>::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl<K, V, S> FromIterator<(<K as WeakElement>::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher + Default,
impl<K, V, S> FromIterator<(<K as WeakElement>::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher + Default,
impl<'a, K, V, S> Index<&'a <K as WeakElement>::Strong> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
impl<'a, K, V, S> Index<&'a <K as WeakElement>::Strong> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
impl<'a, K, V, S> IndexMut<&'a <K as WeakElement>::Strong> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
impl<'a, K, V, S> IndexMut<&'a <K as WeakElement>::Strong> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
impl<K, V, V1, S, S1> PartialEq<PtrWeakKeyHashMap<K, V1, S1>> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
V: PartialEq<V1>,
S: BuildHasher,
S1: BuildHasher,
impl<K, V, V1, S, S1> PartialEq<PtrWeakKeyHashMap<K, V1, S1>> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
V: PartialEq<V1>,
S: BuildHasher,
S1: BuildHasher,
impl<K: WeakElement, V: Eq, S: BuildHasher> Eq for PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for PtrWeakKeyHashMap<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, S> Send for PtrWeakKeyHashMap<K, V, S> where
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for PtrWeakKeyHashMap<K, V, S> where
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> Unpin for PtrWeakKeyHashMap<K, V, S> where
S: Unpin,
impl<K, V, S> UnwindSafe for PtrWeakKeyHashMap<K, V, S> where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more