London | 25-SDC-NOV | Jesus del Moral | Sprint 2 | LRU Cache#137
London | 25-SDC-NOV | Jesus del Moral | Sprint 2 | LRU Cache#137delmorallopez wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
98eddb4 to
4e8b576
Compare
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.
In fact, you can import your LinkedList class from the other exercise, and then store each key-value pairs as a tuple.
Alternatively, you can use OrderedDict directly within LruCache to maintain order.
Could you update your code using one of these approaches?
|
I updated the implementation using OrderedDict as suggested. This approach simplifies the code and better follows the Single-Responsibility Principle, since order maintenance is handled by OrderedDict rather than a custom linked list. The cache now:
|
| <<<<<<< HEAD | ||
| self.cache = {} # key -> node |
There was a problem hiding this comment.
It seems a merge conflict has not yet been properly resolved.
| value = self.cache.pop(key) | ||
| self.cache[key] = value |
There was a problem hiding this comment.
OrderedDict has a built-in method that can replace these two operations.
LRU Cache