[−][src]Struct weak_table::PtrWeakKeyHashMap
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
impl<K: WeakElement, V> PtrWeakKeyHashMap<K, V, RandomState> where
K::Strong: Deref,
[src]
K::Strong: Deref,
pub fn new() -> Self
[src]
Creates an empty PtrWeakKeyHashMap
.
pub fn with_capacity(capacity: usize) -> Self
[src]
Creates an empty PtrWeakKeyHashMap
with the given capacity.
impl<K: WeakElement, V, S: BuildHasher> PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
[src]
K::Strong: Deref,
pub fn with_hasher(hash_builder: S) -> Self
[src]
Creates an empty PtrWeakKeyHashMap
with the given capacity and hasher.
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
[src]
Creates an empty PtrWeakKeyHashMap
with the given capacity and hasher.
pub fn hasher(&self) -> &S
[src]
Returns a reference to the map's BuildHasher
.
pub fn capacity(&self) -> usize
[src]
Returns the number of elements the map can hold without reallocating.
pub fn remove_expired(&mut self)
[src]
Removes all mappings whose keys have expired.
pub fn reserve(&mut self, additional_capacity: usize)
[src]
Reserves room for additional elements.
pub fn shrink_to_fit(&mut self)
[src]
Shrinks the capacity to the minimum allowed to hold the current number of elements.
pub fn len(&self) -> usize
[src]
Returns an over-approximation of the number of elements.
pub fn is_empty(&self) -> bool
[src]
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.
pub fn load_factor(&self) -> f32
[src]
The proportion of buckets that are used.
This is an over-approximation because of expired keys.
pub fn entry(&mut self, key: K::Strong) -> Entry<ByPtr<K>, V>
[src]
Gets the requested entry.
pub fn clear(&mut self)
[src]
Removes all associations from the map.
pub fn get(&self, key: &K::Strong) -> Option<&V>
[src]
Returns a reference to the value corresponding to the key.
pub fn contains_key(&self, key: &K::Strong) -> bool
[src]
Returns true if the map contains the specified key.
pub fn get_mut(&mut self, key: &K::Strong) -> Option<&mut V>
[src]
Returns a mutable reference to the value corresponding to the key.
pub fn insert(&mut self, key: K::Strong, value: V) -> Option<V>
[src]
Unconditionally inserts the value, returning the old value if already present. Does not replace the key.
pub fn remove(&mut self, key: &K::Strong) -> Option<V>
[src]
Removes the entry with the given key, if it exists, and returns the value.
pub fn retain<F>(&mut self, f: F) where
F: FnMut(K::Strong, &mut V) -> bool,
[src]
F: FnMut(K::Strong, &mut V) -> bool,
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,
[src]
&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,
[src]
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,
[src]
&self,
other: &PtrWeakKeyHashMap<K, V1, S1>
) -> bool where
S1: BuildHasher,
Are the keys of self a subset of the keys of other?
impl<K: WeakElement, V, S> PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
[src]
K::Strong: Deref,
pub fn iter(&self) -> Iter<ByPtr<K>, V>
[src]
Gets an iterator over the keys and values.
pub fn keys(&self) -> Keys<ByPtr<K>, V>
[src]
Gets an iterator over the keys.
pub fn values(&self) -> Values<ByPtr<K>, V>
[src]
Gets an iterator over the values.
pub fn iter_mut(&mut self) -> IterMut<ByPtr<K>, V>
[src]
Gets an iterator over the keys and mutable values.
pub fn values_mut(&mut self) -> ValuesMut<ByPtr<K>, V>
[src]
Gets an iterator over the mutable values.
pub fn drain(&mut self) -> Drain<ByPtr<K>, V>
[src]
Gets a draining iterator, which removes all the values but retains the storage.
Trait Implementations
impl<K: Clone, V: Clone, S: Clone> Clone for PtrWeakKeyHashMap<K, V, S>
[src]
fn clone(&self) -> PtrWeakKeyHashMap<K, V, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K, V: Debug, S> Debug for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Debug,
[src]
K: WeakElement,
K::Strong: Debug,
impl<K: WeakElement, V, S: BuildHasher + Default> Default for PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
[src]
K::Strong: Deref,
impl<K: WeakElement, V: Eq, S: BuildHasher> Eq for PtrWeakKeyHashMap<K, V, S> where
K::Strong: Deref,
[src]
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,
[src]
K: 'a + WeakElement,
K::Strong: Clone + Deref,
V: 'a + Clone,
S: BuildHasher,
fn extend<T: IntoIterator<Item = (&'a K::Strong, &'a V)>>(&mut self, iter: T)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<K, V, S> Extend<(<K as WeakElement>::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
[src]
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
fn extend<T: IntoIterator<Item = (K::Strong, V)>>(&mut self, iter: T)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<K, V, S> FromIterator<(<K as WeakElement>::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher + Default,
[src]
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,
[src]
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
type Output = V
The returned type after indexing.
fn index(&self, index: &'a K::Strong) -> &Self::Output
[src]
impl<'a, K, V, S> IndexMut<&'a <K as WeakElement>::Strong> for PtrWeakKeyHashMap<K, V, S> where
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
[src]
K: WeakElement,
K::Strong: Deref,
S: BuildHasher,
impl<K: WeakElement, V, S> IntoIterator for PtrWeakKeyHashMap<K, V, S>
[src]
type Item = (K::Strong, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<ByPtr<K>, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K: WeakElement, V, S> IntoIterator for &'a PtrWeakKeyHashMap<K, V, S>
[src]
type Item = (K::Strong, &'a V)
The type of the elements being iterated over.
type IntoIter = Iter<'a, ByPtr<K>, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K: WeakElement, V, S> IntoIterator for &'a mut PtrWeakKeyHashMap<K, V, S>
[src]
type Item = (K::Strong, &'a mut V)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, ByPtr<K>, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
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,
[src]
K: WeakElement,
K::Strong: Deref,
V: PartialEq<V1>,
S: BuildHasher,
S1: BuildHasher,
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for PtrWeakKeyHashMap<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, S> Send for PtrWeakKeyHashMap<K, V, S> where
K: Send,
S: Send,
V: Send,
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for PtrWeakKeyHashMap<K, V, S> where
K: Sync,
S: Sync,
V: Sync,
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> Unpin for PtrWeakKeyHashMap<K, V, S> where
S: Unpin,
S: Unpin,
impl<K, V, S> UnwindSafe for PtrWeakKeyHashMap<K, V, S> where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,