pub struct WeakHashSet<T, S = RandomState>(/* private fields */);
Expand description
A hash set with weak elements, hashed on element value.
When a weak pointer expires, its mapping is lazily removed.
Implementations§
Source§impl<T: WeakKey> WeakHashSet<T, RandomState>
impl<T: WeakKey> WeakHashSet<T, RandomState>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty WeakHashSet
with the given capacity.
O(n) time
Source§impl<T: WeakKey, S: BuildHasher> WeakHashSet<T, S>
impl<T: WeakKey, S: BuildHasher> WeakHashSet<T, S>
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates an empty WeakHashSet
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 WeakHashSet
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 set empty?
Note that this may return false even if all keys in the set 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 elements.
O(1) time
Sourcepub fn contains<Q>(&self, key: &Q) -> bool
pub fn contains<Q>(&self, key: &Q) -> bool
Returns true if the map contains the specified key.
expected O(1) time; worst-case O(p) time
Sourcepub fn get<Q>(&self, key: &Q) -> Option<T::Strong>
pub fn get<Q>(&self, key: &Q) -> Option<T::Strong>
Gets a strong reference to the given key, if found.
§Examples
use weak_table::WeakHashSet;
use std::rc::{Rc, Weak};
use std::ops::Deref;
let mut set: WeakHashSet<Weak<String>> = WeakHashSet::new();
let a = Rc::new("a".to_owned());
set.insert(a.clone());
let also_a = set.get("a").unwrap();
assert!(Rc::ptr_eq( &a, &also_a ));
expected O(1) time; worst-case O(p) time
Sourcepub fn insert(&mut self, key: T::Strong) -> bool
pub fn insert(&mut self, key: T::Strong) -> bool
Unconditionally inserts the value, returning the old value if already present. Does not replace the key.
expected O(1) time; worst-case O(p) time
Sourcepub fn remove<Q>(&mut self, key: &Q) -> bool
pub fn remove<Q>(&mut self, key: &Q) -> bool
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)
pub fn retain<F>(&mut self, f: F)
Removes all mappings not satisfying the given predicate.
Also removes any expired mappings.
O(n) time
Sourcepub fn is_subset<S1>(&self, other: &WeakHashSet<T, S1>) -> boolwhere
S1: BuildHasher,
pub fn is_subset<S1>(&self, other: &WeakHashSet<T, S1>) -> boolwhere
S1: BuildHasher,
Is self a subset 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
)
Source§impl<T: WeakKey, S> WeakHashSet<T, S>
impl<T: WeakKey, S> WeakHashSet<T, S>
Trait Implementations§
Source§impl<T: Clone, S: Clone> Clone for WeakHashSet<T, S>
impl<T: Clone, S: Clone> Clone for WeakHashSet<T, S>
Source§fn clone(&self) -> WeakHashSet<T, S>
fn clone(&self) -> WeakHashSet<T, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: WeakKey, S> Debug for WeakHashSet<T, S>
impl<T: WeakKey, S> Debug for WeakHashSet<T, S>
Source§impl<T: WeakKey, S: BuildHasher + Default> Default for WeakHashSet<T, S>
impl<T: WeakKey, S: BuildHasher + Default> Default for WeakHashSet<T, S>
Source§impl<T: WeakKey, S: BuildHasher> Extend<<T as WeakElement>::Strong> for WeakHashSet<T, S>
impl<T: WeakKey, S: BuildHasher> Extend<<T as WeakElement>::Strong> for WeakHashSet<T, S>
Source§fn extend<I: IntoIterator<Item = T::Strong>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T::Strong>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)