Skip to content
Rust

std::collections::HashMap API Reference

Rust's HashMap<K, V> — a hash map with quadratic probing and SipHash by default.

By EZ4Code Team

HashMap<K, V>

A hash map implemented with quadratic probing and SipHash 1-3 (or 2-4) hashing.

HashMap::new() -> HashMap<K, V>

Creates an empty HashMap with the default hasher and capacity.

Returns: HashMap<K, V>

map.insert(k: K, v: V) -> Option<V>

Inserts a key-value pair. If the key already existed, the old value is returned.

Returns: Option<V>

map.get<Q: ?Sized>(&self, k: &Q) -> Option<&V>

Returns a reference to the value corresponding to the key.

Returns: Option<&V>

map.remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>

Removes a key from the map, returning the value at the key if the key was previously in the map.

Returns: Option<V>

map.len() -> usize

Returns the number of elements in the map.

Returns: usize

map.contains_key<Q: ?Sized>(&self, k: &Q) -> bool

Returns true if the map contains a value for the specified key.

Returns: bool

map.iter() -> Iter<K, V>

Returns an iterator visiting all key-value pairs in arbitrary order.

Returns: Iter<K, V>

More Rust API References