-
-
Notifications
You must be signed in to change notification settings - Fork 16
ZA | 25-SDC-July | Luke Manyamazi | Sprint 2 | Implement LRU Cache #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ZA | 25-SDC-July | Luke Manyamazi | Sprint 2 | Implement LRU Cache #57
Conversation
91dd7d7 to
2fd0d3e
Compare
OracPrime
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code works, but it doesn't meet the O(1) requirement, so needs a little revision.
| def get(self, key): | ||
| if key in self.cache: | ||
| # Move to most recent position | ||
| self.access_order.remove(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this code works, list.remove has to scan through the list to find key. This isn't O(1), which is the requirement of this test. What O( ) is it?. How else might you manage the order without this?
| self.assertEqual(cache.get("a"), 1) # "a" remains | ||
| self.assertEqual(cache.get("c"), 3) | ||
|
|
||
| def test_complex_usage_pattern(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to see these additional tests. You're the only one I've seen so far that has added these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh thank you, David.
Learners, PR Template
Self checklist
Changelist
Questions