Card 09/ 09

RecapDifficulty: Advanced1 min

One Hash, One Bucket, One Comparison

Five things this topic established, and where each one was.

What the topic established, and which card it was on
The thingWhere
A lookup hashes, picks one bucket, and searches only that bucketHow a Map Finds One Value
A collision keeps both entries; only an equal key replaces a valueWhat Happens When Two Keys Land in the Same Bucket
An overloaded bucket becomes a tree at eight entriesA Bucket That Grew Long Enough to Become a Tree
Sixteen buckets, a load factor of 0.75, and a rebuild that moves everythingWatching a Map Rebuild Itself
A TreeMap refuses null keys because it has to compare themWhy a null Key Is Fine in One Map

A map's speed is borrowed from the key's hashCode, and everything that goes wrong with a map is that loan going bad — keys that all hash alike, keys that hash differently on the way out, or too many entries for the buckets there are.