HashMap::with_capacity
pub static fn with_capacity(int cap) -> HashMap<K, V> Import
Source: use collections::map::{HashMap}; src/collections/map.hy Creates an empty map with room for about cap buckets before it grows.
The bucket count is rounded up to a power of two, at least 8.
Parameters#
| Name | Type |
|---|---|
cap | int |
Returns#
HashMap<K, V>
Examples#
use collections::map::{HashMap};
use tests::assert;
let m: HashMap<int, string> = HashMap::with_capacity(100);
assert!(m.is_empty());
assert!(m.capacity() >= 100);
See also#
HashMap: A hash map from keys of typeKto values of typeV.HashMap::new: Creates an empty map.HashMap::size: Returns the number of entries.HashMap::is_empty: Returnstruewhen the map has no entries.HashMap::capacity: Returns the number of buckets.HashMap::clear: Removes every entry, keeping the bucket count.HashMap::keys: Returns the keys, in insertion order.HashMap::values: Returns the values, in the insertion order of their keys.