A doubly linked list stores links from each node to both its predecessor and successor. In an LRU cache, placing new entries at the front and retaining a tail pointer makes least-recently-used removal take O(1) time. section 7.4.2
An LRU cache uses the list together with a hash table:
- Add new entries at the front of the list. section 7.4.2
LRU cache
A hash table finds a cache entry and points to its list node; the list maintains recency order without duplicating the stored object. The combined structure uses O(n) memory. section 7.4.2
Figure 7.5 Structure of an LRU cache. You can see the tree data elements that are stored for the cache and need to be updated after every operation: (1) The hash table. (2) The head of a doubly-linked list. (3) A pointer to the last element in the list. Notice how each element in the hash table points to a node in the list where all the data is stored. To get from a list entry to the corresponding hash entry, we have to hash the name of the company stored in the node, which is the key for the table. For the sake of simplicity, collision resolution is not considered in this and the following figures.
Trace how the hash table, list head, tail pointer, and shared nodes cooperate in an LRU cache. section 7.4.2

