Back to library

🗺️Hash Maps from Scratch

Stop using dict, set, and HashMap as black boxes — build one from scratch in fourteen days, see exactly how hashing turns keys into bucket indices, and learn why your map slows to a crawl when load factor crosses 0.75.

Foundations14 drops~2-week path · 5–8 min/daytechnology

Phase 1How Hashing Turns Keys Into Addresses

See how hashing turns any key into a bucket index

4 drops
  1. A hash map is just a list with a clever index function

    6 min

    A hash map is just a list with a clever index function

  2. A hash function is a deterministic shredder for any input

    6 min

    A hash function is a deterministic shredder for any input

  3. Buckets are slots, and modulo is how you pick one

    6 min

    Buckets are slots, and modulo is how you pick one

  4. Collisions are mathematically guaranteed, not a bug

    7 min

    Collisions are mathematically guaranteed, not a bug

Phase 2Build a Minimal Hash Map by Hand

Build a minimal hash map with put, get, delete

5 drops
  1. A hash map is a class with one array and a count

    5 min

    A hash map is a class with one array and a count

  2. Put writes to a slot, but first it has to find the right one

    7 min

    Put writes to a slot, but first it has to find the right one

  3. Get walks the chain until it finds your key or runs out

    6 min

    Get walks the chain until it finds your key or runs out

  4. Delete is get with one extra step — splicing the chain

    6 min

    Delete is get with one extra step — splicing the chain

  5. Iteration walks every chain in every bucket

    6 min

    Iteration walks every chain in every bucket

Phase 3Chaining vs Open Addressing in Real Code

Choose chaining or open addressing by tradeoff, not habit

4 drops
  1. Your team's API just slowed 10x — and chaining is the suspect

    7 min

    Your team's API just slowed 10x — and chaining is the suspect

  2. Your map's chains are too cache-unfriendly — what now?

    7 min

    Your map's chains are too cache-unfriendly — what now?

  3. Your map degraded smoothly until load factor 0.85, then fell off a cliff

    7 min

    Your map degraded smoothly until load factor 0.85, then fell off a cliff

  4. The fastest dict in your service spikes to 50ms once an hour — that's a resize

    7 min

    The fastest dict in your service spikes to 50ms once an hour — that's a resize

Phase 4Ship a Hash Map That Resizes Under Load

Ship a hash map that resizes gracefully under load

1 drop
  1. Add resize to your hash map and survive a million inserts

    8 min

    Add resize to your hash map and survive a million inserts

Frequently asked questions

What is a hash map and how does it actually work?
This is covered in the “Hash Maps from Scratch” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why is a hash map lookup O(1) on average but O(n) worst case?
This is covered in the “Hash Maps from Scratch” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What is load factor and why does 0.75 matter?
This is covered in the “Hash Maps from Scratch” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What is the difference between chaining and open addressing?
This is covered in the “Hash Maps from Scratch” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
When does a hash map resize and why is it expensive?
This is covered in the “Hash Maps from Scratch” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.