Grandpa Rimba picks a seed box from its name’s hash: put, get and delete your own seeds, see collisions stack up in one box and what happens when the boxes…
Why it matters
Hash tables are everywhere: JavaScript’s Map and objects, Python’s dict, database indexes, caches. Knowing "key → hash → box" explains why lookups average O(1), why keys must not change, why the order is not insertion order, and why the load factor and resizing decide the speed.
The key idea
Where a key lives is computed, not searched for
Common mistakes
Iterating the keys comes out in another order than they were put in A hash table walks box by box, so its order is the boxes’ order, and it changes when the table grows. JavaScript’s Map is guaranteed insertion order; use it when order matters.
A key that was found is suddenly not found If a key’s hash changes after it is stored (an object hashed by its content, and the content edited), a lookup works out another box. Keys must stay fixed; JavaScript’s Map compares objects by identity, not content.
A hash map’s speed collapses though it is meant to be fast On average O(1), but a bad hash or a high load piles keys into one box, and every lookup compares its whole chain: O(n). Short chains are the key.
Try it in this playground
Store a seed Hash, remainder, box number: no searching.
Make a collision Two seeds in one box: the chain grows.
Watch the boxes grow Past a load of 0.75, the boxes double and every packet is worked out again.
Try a bad hash The name’s length as the hash: three or more seeds in one box.