pub struct HashMap<K, V, S = RandomState> { /* private fields */ }
Implementations§
Source§impl<K, V> HashMap<K, V>
impl<K, V> HashMap<K, V>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty HashMap
.
The hash map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty HashMap
with the specified capacity.
The hash map will be able to hold at least capacity
elements without
reallocating. If capacity
is 0, the hash map will not allocate.
Source§impl<K: Hash, V, S: BuildHasher> HashMap<K, V, S>
impl<K: Hash, V, S: BuildHasher> HashMap<K, V, S>
Source§impl<K, V, S: Clone> HashMap<K, V, S>
impl<K, V, S: Clone> HashMap<K, V, S>
Sourcepub fn with_hasher(hasher: S) -> Self
pub fn with_hasher(hasher: S) -> Self
Creates an empty HashMap
which will use the given hash builder to hash
keys.
The created map has the default initial capacity.
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.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
Creates an empty HashMap
with the specified capacity, using hash_builder
to hash the keys.
The hash map will be able to hold at least capacity
elements without
reallocating. If capacity
is 0, the hash map will not allocate.
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.