Hash log
How hash tables work
A hash table stores data in buckets. A hash function maps each key to a bucket index using modulo.
A collision happens when two keys land in the same bucket. Good hash functions spread keys evenly; bad ones (like using string length) cluster them.
Try these experiments:
-
Switch to
lengthhash and add words of different lengths -- see how same-length words always collide -
Switch to
charSumand add anagrams (listen, silent) -- they collide because they have the same character sum - Slide the bucket count down to 2 and watch collisions pile up
- Compare
djb2vsFNV-1adistribution on the same words