NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | implement_lru_cache#175
NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | implement_lru_cache#175ZabihollahNamazi wants to merge 3 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
To better adhere to the Single-Responsibility Principle (SRP) from SOLID design principles, it's preferable to implement the "doubly linked list" and the "LRU Cache" as separate classes, with the linked list used inside LruCache to manage ordering.
Alternatively, use OrderedDict to maintain order.
Could you update your code using one of these approaches?
| class LruCache: | ||
| def __init__(self, limit: int): | ||
| if limit <= 0: | ||
| raise ValueError("Cache limit must be greater than 0") | ||
|
|
||
| self.limit = limit | ||
| self.lookup = {} | ||
| self.head = None | ||
| self.tail = None | ||
|
|
There was a problem hiding this comment.
This LruCache implementation is still tightly coupled with the code of a linked list.
How could you reuse your Linked List implementation in your LruCache without copying its code?
There was a problem hiding this comment.
I moved the LinkedList code into its own file linked_list.py and imported it into LruCache
|
Changes look good. |
|
Closing PR because the SDC run has finished. Feel free to re-open if you're still working on it. |
Self checklist
Hi! Could you please check my code?
The code handles all cache operations, updates eviction orders correctly, and keeps everything running fast speed.All 5 tests are passing perfectly. Thank you!