← capítulo

Hash functions

Turn a key into an integer, spread evenly. A table is only as good as its hash.

The one rule

Watch a good vs a bad hash

FNV-1a stays even blue. First-letter hash lights up a few buckets red. Same words, same buckets — only the mixing differs.

Distribution: even vs skyline

First-letter: 51 words in one bucket, 11 buckets empty. Chi-square 509 vs 15.

Match the hash to the job

Takeaway

Mix the whole key, keep it fast. Use hash(). Next: sets and multisets — hash tables of keys.