01Sets and maps
Two everyday tools are built on hash tables:
- A set stores unique keys and answers "is x in it?". C++
unordered_set, Pythonset, JavaHashSet. - A map (dictionary) stores key → value pairs: word → count, user id → profile. C++
unordered_map, Pythondict, JavaHashMap.
The idea: a hash function h(k) turns any key, a number or a string, into an index of an array of buckets. To insert, compute h(k) and put the key there. To look up, compute h(k) again and look in that one bucket. No scanning, no sorting: the key itself tells you where it lives.