pub struct HashMapBuilder<K, V, S = RandomState> { /* private fields */ }
Expand description
A builder for a HashMap
.
§Examples
use papaya::{HashMap, ResizeMode};
use seize::Collector;
use std::collections::hash_map::RandomState;
let map: HashMap<i32, i32> = HashMap::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 map.
.build();
Implementations§
Source§impl<K, V> HashMapBuilder<K, V>
impl<K, V> HashMapBuilder<K, V>
Sourcepub fn hasher<S>(self, hasher: S) -> HashMapBuilder<K, V, S>
pub fn hasher<S>(self, hasher: S) -> HashMapBuilder<K, V, S>
Set the hash builder used to hash keys.
Warning: hash_builder
is normally randomly generated, and is designed
to allow HashMaps 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 HashMap to be useful, see its documentation for details.
Source§impl<K, V, S> HashMapBuilder<K, V, S>
impl<K, V, S> HashMapBuilder<K, V, S>
Sourcepub fn capacity(self, capacity: usize) -> HashMapBuilder<K, V, S>
pub fn capacity(self, capacity: usize) -> HashMapBuilder<K, V, S>
Set the initial capacity of the map.
The table should be able to hold at least capacity
elements before resizing.
However, the capacity is an estimate, and the table may prematurely resize due
to poor hash distribution. If capacity
is 0, the hash map 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 map. 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 map must be produced by
the provided collector
.