pub struct SparseSet<K, H = StdHash, E = StdEq, P = PowerOfTwo<2>, S = Medium> { /* private fields */ }Expand description
A hash set that trades a little insert speed for low memory use.
Type parameters match crate::SparseMap without the value type.
Implementations§
Source§impl<K> SparseSet<K, StdHash, StdEq, PowerOfTwo<2>, Medium>
impl<K> SparseSet<K, StdHash, StdEq, PowerOfTwo<2>, Medium>
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty set with no allocation.
Construction places no bound on K. The Hash and Eq bounds belong
to the operations that hash or compare a key.
Sourcepub fn with_bucket_count(bucket_count: usize) -> Self
pub fn with_bucket_count(bucket_count: usize) -> Self
An empty set sized for at least bucket_count buckets.
§Panics
Panics when bucket_count exceeds the policy maximum.
Sourcepub fn try_with_bucket_count(bucket_count: usize) -> Result<Self, LengthError>
pub fn try_with_bucket_count(bucket_count: usize) -> Result<Self, LengthError>
An empty set sized for at least bucket_count buckets, fallibly.
Source§impl<K, B, P, S> SparseSet<K, StdHash<B>, StdEq, P, S>
impl<K, B, P, S> SparseSet<K, StdHash<B>, StdEq, P, S>
Sourcepub fn with_hasher_and_bucket_count(bucket_count: usize) -> Self
pub fn with_hasher_and_bucket_count(bucket_count: usize) -> Self
An empty set that hashes with B and uses policy P and sparsity S.
§Panics
Panics when bucket_count exceeds the policy maximum.
Source§impl<K, H, E, P, S> SparseSet<K, H, E, P, S>
impl<K, H, E, P, S> SparseSet<K, H, E, P, S>
Sourcepub fn with_parts(bucket_count: usize, hash: H, key_eq: E) -> Self
pub fn with_parts(bucket_count: usize, hash: H, key_eq: E) -> Self
Build a set from explicit hasher, comparator, policy, and sparsity.
§Panics
Panics when bucket_count exceeds the policy maximum.
Sourcepub fn bucket_count(&self) -> usize
pub fn bucket_count(&self) -> usize
The logical bucket count. Zero for a fresh set.
Sourcepub fn max_bucket_count(&self) -> usize
pub fn max_bucket_count(&self) -> usize
The largest bucket count the set can hold.
Sourcepub fn load_factor(&self) -> f32
pub fn load_factor(&self) -> f32
Ratio of keys to buckets. Zero for an empty set.
Sourcepub fn max_load_factor(&self) -> f32
pub fn max_load_factor(&self) -> f32
The maximum load factor before a grow.
Sourcepub fn set_max_load_factor(&mut self, ml: f32)
pub fn set_max_load_factor(&mut self, ml: f32)
Set the maximum load factor, clamped to [0.1, 0.8].
Sourcepub fn hash_function(&self) -> &H
pub fn hash_function(&self) -> &H
The hasher.
Sourcepub fn reserve(&mut self, count: usize)
pub fn reserve(&mut self, count: usize)
Reserve room for count keys without exceeding the load factor.
Sourcepub fn contains_precalc<Q>(&self, key: &Q, hash: usize) -> bool
pub fn contains_precalc<Q>(&self, key: &Q, hash: usize) -> bool
Whether key is present, using a precomputed hash.
Sourcepub fn count_precalc<Q>(&self, key: &Q, hash: usize) -> usize
pub fn count_precalc<Q>(&self, key: &Q, hash: usize) -> usize
1 when key is present, 0 otherwise, using a precomputed hash.
Sourcepub fn equal_range<Q>(&self, key: &Q) -> EqualRange<'_, K>
pub fn equal_range<Q>(&self, key: &Q) -> EqualRange<'_, K>
The range of keys equal to key.
A set holds at most one key per value, so the range is empty or a single
key. The returned iterator yields &K and has length 0 or 1.
Sourcepub fn equal_range_precalc<Q>(&self, key: &Q, hash: usize) -> EqualRange<'_, K>
pub fn equal_range_precalc<Q>(&self, key: &Q, hash: usize) -> EqualRange<'_, K>
The range of keys equal to key, using a precomputed hash.
Sourcepub fn erase_range(&mut self, skip: usize, count: usize)
pub fn erase_range(&mut self, skip: usize, count: usize)
Remove count keys starting at iteration index skip.
Erasing leaves a tombstone. The walk is a single forward pass.
Sourcepub fn erase_all(&mut self)
pub fn erase_all(&mut self)
Remove every key, leaving tombstones. Keeps the bucket count.
Use SparseSet::clear to also reset the tombstones and counters.
Source§impl<K, H, E, P, S> SparseSet<K, H, E, P, S>where
K: Serialize,
impl<K, H, E, P, S> SparseSet<K, H, E, P, S>where
K: Serialize,
Sourcepub fn serialize<Sz: Serializer>(&self, serializer: &mut Sz)
pub fn serialize<Sz: Serializer>(&self, serializer: &mut Sz)
Write the set through serializer in protocol order.
Source§impl<K, H, E, P, S> SparseSet<K, H, E, P, S>where
H: HashKey<K> + Clone,
E: EqKey<K, K> + Clone,
P: GrowthPolicy,
S: Sparsity,
K: Serialize + Deserialize,
impl<K, H, E, P, S> SparseSet<K, H, E, P, S>where
H: HashKey<K> + Clone,
E: EqKey<K, K> + Clone,
P: GrowthPolicy,
S: Sparsity,
K: Serialize + Deserialize,
Sourcepub fn deserialize_with<D: Deserializer>(
deserializer: &mut D,
hash_compatible: bool,
hash: H,
key_eq: E,
) -> Result<Self, DeserializeError>
pub fn deserialize_with<D: Deserializer>( deserializer: &mut D, hash_compatible: bool, hash: H, key_eq: E, ) -> Result<Self, DeserializeError>
Read a set written by SparseSet::serialize.
Trait Implementations§
impl<K, H, E, P, S> Eq for SparseSet<K, H, E, P, S>
Source§impl<K, H, E, P, S> Extend<K> for SparseSet<K, H, E, P, S>
impl<K, H, E, P, S> Extend<K> for SparseSet<K, H, E, P, S>
Source§fn extend<I: IntoIterator<Item = K>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = K>>(&mut self, iter: I)
Insert every key from iter. Keys already present are ignored.
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)