Struct HashMapBuilder

Source
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>

Source

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>

Source

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.

Source

pub fn resize_mode(self, resize_mode: ResizeMode) -> Self

Set the resizing mode of the map. See ResizeMode for details.

Source

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.

Source

pub fn build(self) -> HashMap<K, V, S>

Construct a HashMap from the builder, using the configured options.

Trait Implementations§

Source§

impl<K, V, S> Debug for HashMapBuilder<K, V, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, S = RandomState> !Freeze for HashMapBuilder<K, V, S>

§

impl<K, V, S> RefUnwindSafe for HashMapBuilder<K, V, S>

§

impl<K, V, S> Send for HashMapBuilder<K, V, S>
where S: Send, K: Send, V: Send,

§

impl<K, V, S> Sync for HashMapBuilder<K, V, S>
where S: Sync, K: Sync, V: Sync,

§

impl<K, V, S> Unpin for HashMapBuilder<K, V, S>
where S: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, S = RandomState> !UnwindSafe for HashMapBuilder<K, V, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.