Struct BiMapBuilder

Source
pub struct BiMapBuilder<LH, RH, B> { /* private fields */ }
Expand description

A builder for the bimap. Allows for the parameters used to tune the BiMap to be configured.

Implementations§

Source§

impl BiMapBuilder<RandomState, RandomState, DefaultBitField>

Source

pub fn new() -> Self

Create new builder, ready to be configured.

let map: BiMap<String, String> = BiMapBuilder::new().finish();
Source§

impl<LH: BuildHasher, RH: BuildHasher, B: BitField> BiMapBuilder<LH, RH, B>

Source

pub fn capacity(self, capacity: usize) -> Self

Sets the initial capacity of the bimap. It is not guaranteed that at least capacity elements can be inserted before the map needs to be resized, but it is likely. The only reason the map would need to be resized before that number of elements was inserted is due to a large number of hash collisions.

let map: BiMap<String, String> = BiMapBuilder::new().capacity(1024).finish();
Source

pub fn left_hasher<LH2: BuildHasher>( self, hasher: LH2, ) -> BiMapBuilder<LH2, RH, B>

Sets the hasher used for left values. By default, the hashmap will use the hashing algorithm used in the standard library hashmap, which is randomly generated and designed to be resistant to DoS attacks. Changing this hasher may lead to hash collisions and performance issues, so do so with care.

use std::collections::hash_map::RandomState;

let map: BiMap<String, String> = BiMapBuilder::new()
            .left_hasher(RandomState::new())
            .finish();
Source

pub fn right_hasher<RH2: BuildHasher>( self, hasher: RH2, ) -> BiMapBuilder<LH, RH2, B>

Sets the hasher used for right values. By default, the hashmap will use the hashing algorithm used in the standard library hashmap, which is randomly generated and designed to be resistant to DoS attacks. Changing this hasher may lead to hash collisions and performance issues, so do so with care.

use std::collections::hash_map::RandomState;

let map: BiMap<String, String> = BiMapBuilder::new()
            .right_hasher(RandomState::new())
            .finish();
Source

pub fn bitfield<B2: BitField>(self) -> BiMapBuilder<LH, RH, B2>

Sets the size of the bitfield used internall by the hopscotch hashing algorithm. The hopscotch hashing algorithm guarantees that each key is stored within the same “neighbourhood” as its ideal location, regardless of hash collisions. The size of the neighbourhood - and therefore the maximum offset between a key’s real location and its ideal location - is equal to the number of bits in this bitfield type. This can be tuned to control the expected number of cache misses needed to do a lookup.

let map: BiMap<String, String, _, _, u16> = BiMapBuilder::new()
            .bitfield::<u16>()
            .finish();
Source

pub fn finish<L, R>(self) -> BiMap<L, R, LH, RH, B>

Takes a completely configured builder, and creates a new BiMap with the specified configurations.

let map: BiMap<String, String> = BiMapBuilder::new().finish();

Trait Implementations§

Source§

impl<LH: Debug, RH: Debug, B: Debug> Debug for BiMapBuilder<LH, RH, B>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for BiMapBuilder<RandomState, RandomState, DefaultBitField>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<LH, RH, B> Freeze for BiMapBuilder<LH, RH, B>
where LH: Freeze, RH: Freeze,

§

impl<LH, RH, B> RefUnwindSafe for BiMapBuilder<LH, RH, B>

§

impl<LH, RH, B> Send for BiMapBuilder<LH, RH, B>
where LH: Send, RH: Send, B: Send,

§

impl<LH, RH, B> Sync for BiMapBuilder<LH, RH, B>
where LH: Sync, RH: Sync, B: Sync,

§

impl<LH, RH, B> Unpin for BiMapBuilder<LH, RH, B>
where LH: Unpin, RH: Unpin, B: Unpin,

§

impl<LH, RH, B> UnwindSafe for BiMapBuilder<LH, RH, B>
where LH: UnwindSafe, RH: UnwindSafe, B: UnwindSafe,

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.