trekhleb / javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
185.07k stars 29.85k forks source link

Add an example of the LRU (Least Recently Used) Cache implementation #980

Closed trekhleb closed 1 year ago

trekhleb commented 1 year ago

The LRUCache implementation example. The solution uses a HashMap for fast O(1) cache items access, and a DoublyLinkedList for fast O(1) cache items promotions and eviction (to keep the maximum allowed cache capacity).