⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@Luke-Manyamazi
Copy link

@Luke-Manyamazi Luke-Manyamazi commented Nov 10, 2025

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  • Implemented get and put methods with O(1) time complexity
  • Used hash map + doubly linked list for efficient access tracking
  • Handles cache eviction in put when capacity is exceeded

Questions

  1. Is the current LRU eviction policy in put correct?
  2. Should we add utility methods like size() or clear()?

@Luke-Manyamazi Luke-Manyamazi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Nov 10, 2025
Copy link

@OracPrime OracPrime left a 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)

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):

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh thank you, David.

@OracPrime OracPrime added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Complexity The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants