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<LH: BuildHasher, RH: BuildHasher, B: BitField> BiMapBuilder<LH, RH, B>
impl<LH: BuildHasher, RH: BuildHasher, B: BitField> BiMapBuilder<LH, RH, B>
Sourcepub fn capacity(self, capacity: usize) -> Self
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();Sourcepub fn left_hasher<LH2: BuildHasher>(
self,
hasher: LH2,
) -> BiMapBuilder<LH2, RH, B>
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();Sourcepub fn right_hasher<RH2: BuildHasher>(
self,
hasher: RH2,
) -> BiMapBuilder<LH, RH2, B>
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();Sourcepub fn bitfield<B2: BitField>(self) -> BiMapBuilder<LH, RH, B2>
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();