Hash function
A calculation that turns a key into a number. In a hash table, that number divided by the number of buckets gives the spot where it's stored.
Example
With 100 buckets and hash(key) = key, the key 12836 goes to bucket 12836 % 100 = 36.
Test yourself: Hash function
Hash tables
With 100 buckets and hash(key) = key, the key 4521 goes to bucket ___.
4521 % 100 = 21: the remainder of dividing by 100 is the last 2 digits. It always gives a number from 0 to 99.
Hash algorithms
If a hash algorithm gave a different result each time for the same key, the table would find nothing.
You store "ana" in bucket 7 and, when looking it up, the hash gives 3: you check the wrong bucket. It has to give 7 all 1,000 times.
Hash algorithms
You download a 2 GB file and the page shows its hash. What's it for?
You compute your 2 GB file's hash: if it matches the published one, not a single byte was corrupted or changed in the download.
0/3
â–¶ PlayLessons that use it
Hash tables
From key to slot in 1 calculation
Hash collisions
When 2 keys want the same spot
Hash algorithms
A good hash spreads evenly
Choosing how to search
Brute force or using the order
Sharding
Splitting the database into pieces
Consistent hashing
A ring to split the load
Generating unique keys
Where 3I71d3o comes from
