On this page
  1. HashMap
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

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

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