12. Data structures the kernel actually uses
One-liner. Systems code picks structures for cache behaviour and concurrency, not big-O alone.
Memorize
- Hash table: O(1) average; chaining vs open addressing; load factor controls collisions; Robin Hood hashing bounds probe length.
- Radix tree (xarray): page cache lookup by index — no rebalancing, good locality.
- Red-black tree: ordered intervals and timers; O(log n) with bounded height.
- Skip list: probabilistic ordered map; used in Redis sorted sets, simpler concurrent variants.
- Bloom filter: no false negatives, tunable false positives;
m = −n ln p / (ln 2)²bits. - Ring buffer: fixed-size SPSC/MPMC queues; cache-friendly, no allocation.
- LRU = hash map + intrusive doubly linked list; intrusive lists avoid per-entry allocation.
- Slab/size-class allocators trade internal fragmentation for speed and O(1) allocation.
Trap. Picking a hash table for range queries, or a tree for pointer-chasing-free iteration. Do this. Match the access pattern: point lookup, ordered scan, membership, FIFO.
Check
A Bloom filter answers "definitely not present" with certainty. What does it trade away?
Why
No false negatives, but a tunable false-positive rate; you confirm hits with the real store.