</>
Plan du cours — 22/66

HashMap et HashSet

Intermédiaire
use std::collections::{HashMap, HashSet};

let mut scores: HashMap<String, u32> = HashMap::new();
scores.insert("Alice".to_string(), 10);

if let Some(s) = scores.get("Alice") { println!("{s}"); }

// entry : insérer ou modifier (compter des occurrences)
*scores.entry("Bob".to_string()).or_insert(0) += 1;

for (nom, score) in &scores { println!("{nom}: {score}"); }

let mut uniques: HashSet<i32> = HashSet::new();
uniques.insert(1);

Pour un ordre déterministe, utilisez BTreeMap / BTreeSet (triés par clé).