Curriculum Collections & iteration Hash maps
Hash maps
HashMap<K, V> replaces many TypeScript object-as-map patterns, but lookups return Option<&V> and insertion may move keys and values. Planned exercises: 1. choose HashMap. 2. recognise insert. 3. choose .get() return type. 4. fill an import from std::collections. 5. fill entry(...).or_insert(...). 6. write a frequency counter. 7. write a lookup with a fallback. 8. translate TS record code. 9. fix a borrowed-key lookup without cloning unnecessarily.
Exercises
9 ready
01
pick one
TypeScript writes a string-keyed integer map as
02
pick one
Add the key String::from("alice") with value 5 to a
03
pick one
Given m: HashMap<String, i32>, what does m.get("alice")
04
fill blanks
Fill the type name in the import that brings the standard
05
fill blanks
Fill the method that returns the map's Entry API — used for
06
write a program
Write a word-frequency counter. Given
07
write a program
Write get_or_default(m: &HashMap<String, i32>, key: &str) -> i32
08
write a program
Translate the TypeScript record-as-inventory pattern to Rust.
09
write a program
This program over-clones — lookup takes key: String,