On this page
HashMap
Prev: collections | Up: collections | Next: `HashSet`
Rel: collections, rust/builtins
Ref: Rust std — HashMap
Tags: #public #prog #rust #stdlib #collections #tier/core
Signature & Overview
HashMap<K, V>
SwissTable hash map with DoS-resistant SipHash by default and ergonomic .entry() API.
Notes & Pitfalls
- Randomized SipHash by default (DoS-resistant): Iteration order is non-deterministic across runs.
- Use
.entry(k).or_insert(...)to avoid hashing the same key twice during insert-or-update patterns.
Example
use std::collections::HashMap;
fn main() {
let mut counts = HashMap::new();
for word in ["rust", "is", "fast", "rust"] {
*counts.entry(word).or_insert(0) += 1;
}
assert_eq!(counts["rust"], 2);
}
Linked from
Related notes
- tuts/rust/std/collections/HashSet Linked here; links to this page; shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/collections Linked here; links to this page; shared tags: #collections, #prog, #rust, #stdlib
- tuts/rust/builtins Linked here; shared tags: #prog, #rust
- tuts/rust/std/collections/BinaryHeap shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/collections/BTreeMap shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/collections/VecDeque shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/error_and_fmt/Display shared tags: #prog, #rust, #stdlib, #tier
- tuts/rust/std/error_and_fmt/Error shared tags: #prog, #rust, #stdlib, #tier
- tuts/rust/std/error_and_fmt/format shared tags: #prog, #rust, #stdlib, #tier
- tuts/rust/std/ffi/CString shared tags: #prog, #rust, #stdlib, #tier