Skip to content

An LRU Cache implemented in Python using doubly linked list and hashmap for O(1) operations, demonstrating system design and data structure proficiency.

Notifications You must be signed in to change notification settings

AlexQuinn-Analytics/python-lru-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€โœจ LRU Cache Implementation in Python

๐Ÿ”– Description:
An efficient Least Recently Used (LRU) Cache implemented in Python using ๐Ÿ—‚๏ธ doubly linked list and ๐Ÿ”‘ hashmap for O(1) operations.


๐Ÿ› ๏ธ Features

โœ… Supports get(key) and put(key, value) in O(1) time
๐Ÿ” Automatically evicts the least recently used item when capacity is exceeded
๐Ÿงฉ Uses:

  • ๐Ÿ—ƒ๏ธ Doubly Linked List to maintain usage order
  • โšก Hash Map (dict) for quick key-node lookup

๐Ÿ“‚ Files

  • lru_cache.py โ€“ main implementation and example usage

๐Ÿ’ป Example Usage

lru = LRUCache(3)
lru.put(1, 1)
lru.put(2, 2)
lru.put(3, 3)
print(lru.get(1))  # Output: 1
lru.put(4, 4)      # Evicts key 2
print(lru.get(2))  # Output: -1
print(lru.get(3))  # Output: 3
print(lru.get(4))  # Output: 4
๐ŸŽฏ Why This Project?
๐Ÿ’ก For CS (Computer Science) :

Demonstrates proficiency in classic data structures ๐Ÿ—๏ธ and algorithm design โš™๏ธ

Shows understanding of system performance optimization ๐Ÿš€ via caching strategies

๐Ÿ“Š For DS (Data Science) :

Highlights coding ๐Ÿ’ป and logical thinking ๐Ÿง  beyond library usage

LRU cache logic is commonly used in feature stores, database query optimization, and large-scale data pipelines

๐Ÿ”ฎ Future Work
๐ŸŒŸ Implement LFU Cache for frequency-based eviction
๐ŸŒ Build a RESTful API integrating this cache with a database
โš–๏ธ Compare with Pythonโ€™s built-in OrderedDict LRU implementations

๐Ÿ™‹โ€โ™‚๏ธ Author
Shuai Qian ๏ผˆAlex Quinn๏ผ‰

About

An LRU Cache implemented in Python using doubly linked list and hashmap for O(1) operations, demonstrating system design and data structure proficiency.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages