Type Definition bevy_utils::HashMap [−][src]
pub type HashMap<K, V> = HashMap<K, V, RandomState>;
Expand description
A HashMap
implementing aHash
, a high
speed keyed hashing algorithm intended for use in in-memory hashmaps.
aHash
is designed for performance and is NOT cryptographically secure.
Construction
Users may be surprised when a HashMap
cannot be constructed with HashMap::new()
:
ⓘ
use bevy_utils::HashMap;
// Produces an error like "no function or associated item named `new` found [...]"
let map: HashMap<String, String> = HashMap::new();
The standard library’s HashMap::new
is
implemented only for HashMap
s which use the
DefaultHasher
, so it’s not
available for Bevy’s HashMap
.
However, an empty HashMap
can easily be constructed using the Default
implementation:
use bevy_utils::HashMap;
// This works!
let map: HashMap<String, String> = HashMap::default();
assert!(map.is_empty());
Trait Implementations
Creates an empty HashMap
with the specified capacity with aHash.
The hash map will be able to hold at least capacity
elements without
reallocating. If capacity
is 0, the hash map will not allocate.
Examples
use bevy_utils::{HashMap, AHashExt};
let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
assert!(map.capacity() >= 10);