Skip to content
Combining: Hash Map + DLL
step 1/5

Reading — step 1 of 5

Read

~1 min readThe Doubly-Linked List + Hash Map

Combining: Hash Map + DLL

The classic O(1) LRU = hash map (key -> Node) + doubly-linked list (recency order).

python

Both get and put are O(1):

  • Hash map lookup: O(1)
  • DLL remove + add_front: O(1) (we have direct node pointers, no scan)
  • Eviction: O(1) (tail.prev is always the LRU)

This is THE classic LRU. Almost every production cache uses this structure.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…