pub struct HashSetBuilder<K, S = RandomState> { /* private fields */ }
Expand description
A builder for a HashSet
.
§Examples
use papaya::{HashSet, ResizeMode};
use seize::Collector;
use std::collections::hash_map::RandomState;
let set: HashSet<i32> = HashSet::builder()
// Set the initial capacity.
.capacity(2048)
// Set the hasher.
.hasher(RandomState::new())
// Set the resize mode.
.resize_mode(ResizeMode::Blocking)
// Set a custom garbage collector.
.collector(Collector::new().batch_size(128))
// Construct the hash set.
.build();
Implementations§
Source§impl<K> HashSetBuilder<K>
impl<K> HashSetBuilder<K>
Sourcepub fn hasher<S>(self, hasher: S) -> HashSetBuilder<K, S>
pub fn hasher<S>(self, hasher: S) -> HashSetBuilder<K, S>
Set the hash builder used to hash keys.
Warning: hash_builder
is normally randomly generated, and is designed
to allow HashSets to be resistant to attacks that cause many collisions
and very poor performance. Setting it manually using this function can
expose a DoS attack vector.
The hash_builder
passed should implement the BuildHasher
trait for
the HashSet to be useful, see its documentation for details.
Source§impl<K, S> HashSetBuilder<K, S>
impl<K, S> HashSetBuilder<K, S>
Sourcepub fn capacity(self, capacity: usize) -> HashSetBuilder<K, S>
pub fn capacity(self, capacity: usize) -> HashSetBuilder<K, S>
Set the initial capacity of the set.
The set should be able to hold at least capacity
elements before resizing.
However, the capacity is an estimate, and the set may prematurely resize due
to poor hash distribution. If capacity
is 0, the hash set will not allocate.
Sourcepub fn resize_mode(self, resize_mode: ResizeMode) -> Self
pub fn resize_mode(self, resize_mode: ResizeMode) -> Self
Set the resizing mode of the set. See ResizeMode
for details.
Sourcepub fn collector(self, collector: Collector) -> Self
pub fn collector(self, collector: Collector) -> Self
Set the seize::Collector
used for garbage collection.
This method may be useful when you want more control over garbage collection.
Note that all Guard
references used to access the set must be produced by
the provided collector
.