Step 3 of 5
A string-keyed map with erase
A map stores key/value pairs in the buckets instead of bare keys. Erasing finds the pair in its bucket and removes it from the list.
std::hash<std::string> hashes strings. (Under the hood it runs something like the FNV or MurmurHash functions over the bytes.)
Your turn: write StrMap (a fixed 64 buckets is fine here) with:
void put(const std::string& key, int value): insert or overwriteconst int* get(const std::string& key) const: pointer to the value, ornullptrbool erase(const std::string& key)std::size_t size() const
Previous: Load factor and rehashing Next: Hashing your own keys