# Ch 20: Hash Tables

> Study guide to Crafting Interpreters chapter 20. A hash table from scratch with open addressing and linear probing, FNV-1a hashing, tombstones for deletion…

Updated October 20, 2026.

## Summary {#summary}

Crafting Interpreters chapter 20, Hash Tables: A hash table from scratch with open addressing and linear probing, FNV-1a hashing, tombstones for deletion, growth by load factor, and string interning so string equality becomes pointer equality. Budget about 7 hours; the book's `chap20_hash` tests check your code.

## Key facts {#key-facts}

- Week 18 of 145 on the cracked.guide path, in [Crafting Interpreters](https://cracked.guide/crafting-interpreters).
- Time budget: about 7 hours.
- Part of the book: clox (bytecode VM, C).
- Verified on cracked.guide when the official `chap20_hash` tests pass on GitHub Actions.
- 3 challenges at the end of the chapter.
- Terms it teaches: [String interning](https://cracked.guide/glossary/string-interning), [Open addressing](https://cracked.guide/glossary/open-addressing).

## Week 18 goals {#objectives}

By the end of week 18 you can:

- Implement an open-addressing hash table with linear probing and tombstones.
- Compute FNV-1a hashes and turn them into bucket indexes.
- Explain how interning lets string equality compare pointers.

## This week's steps {#steps}

- Read the chapter: Implement, then write a small stress test that inserts and deletes many keys and checks lookups.
- Write the code in your lox repo: Type it into clox/ (C) yourself as you read, and get it running.
- Do the challenges (1–3): Challenge 1 (support non-string keys) and challenge 2 (tune and compare hash table designs) are great; challenge 3 (benchmarking) pairs well with 2.
- Push and let the tests verify it: Your repo runs the book's chap20_hash tests on every push; passing marks this done.

## Why it matters {#why}

Hash tables are the most used data structure in practice. Building one yourself demystifies every dictionary and map you use, and Knuth 6.4 later analyzes exactly this design.

## How to approach it {#approach}

Implement, then write a small stress test that inserts and deletes many keys and checks lookups. Re-read the tombstone section twice; it is the subtle part.

## Challenges {#challenges}

3 challenges at the end of the chapter.

Challenge 1 (support non-string keys) and challenge 2 (tune and compare hash table designs) are great; challenge 3 (benchmarking) pairs well with 2.

## Common traps {#traps}

- Not treating tombstones correctly on insert versus lookup.
- Infinite loop when the table has no empty slots (load factor too high).
- Counting tombstones in the load factor or not, inconsistently.

## Links {#links}

- [Read the chapter: Ch 20: Hash Tables](https://craftinginterpreters.com/hash-tables.html)
- [Official repo: book source, both interpreters, test suite](https://github.com/munificent/craftinginterpreters)
- [Running the official test suite against your own interpreter (repo README)](https://github.com/munificent/craftinginterpreters#testing-your-implementation)
- [Wikipedia: Open addressing](https://en.wikipedia.org/wiki/Open_addressing)
- [Wikipedia: String interning](https://en.wikipedia.org/wiki/String_interning)
- [Hacker News: Hash tables with open addressing](https://news.ycombinator.com/item?id=13270556)

---

Source: https://cracked.guide/guide/ci-20
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
