Skip to content

London|25-SDC-November|Donara Blanc |Sprint 2| Lru-cache#90

Open
donarbl wants to merge 2 commits intoCodeYourFuture:mainfrom
donarbl:sprint-2-lru-cache
Open

London|25-SDC-November|Donara Blanc |Sprint 2| Lru-cache#90
donarbl wants to merge 2 commits intoCodeYourFuture:mainfrom
donarbl:sprint-2-lru-cache

Conversation

@donarbl
Copy link

@donarbl donarbl commented Jan 31, 2026

  • 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

Change List

I separated DoublyLinkedList from LruCache (SRP) to follos the recommendation of Solid design principle

@github-actions

This comment has been minimized.

@donarbl donarbl 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 Jan 31, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 31, 2026
@github-actions

This comment has been minimized.

@donarbl donarbl changed the title London|25-SDC-November|Donara Blanc |Sprint2| Lru-cache London|25-SDC-November|Donara Blanc |Sprint 2| Lru-cache Jan 31, 2026
@donarbl donarbl added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 31, 2026
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

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, OrderedDict can be used directly within LruCache to maintain order.

Could you update your code using one of these approaches?

@cjyuan cjyuan 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 Feb 26, 2026
refactored by following the recommendation to separate DoublyLinkedList from LruCache
@donarbl
Copy link
Author

donarbl commented Feb 27, 2026

Thank you for suggestion and it is done

Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

I don't think the current implementation can pass the tests in lru_cache_test.py.

self.head = None
self.tail = None

def _add_to_head(self, node):
Copy link

Choose a reason for hiding this comment

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

What's your reason to to make the methods "private" (by naming convention)?

This could be just a normal linked list.
You could even import the LinkedList you implemented in the other exercise and use it here, and represent the value of data as (key, value).

Comment on lines +89 to +90
new_node = _Node(key, value)
self._add_to_head(new_node)
Copy link

Choose a reason for hiding this comment

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

It would make the LinkedList easier to use if add_to_head() is designed in such a way that the caller can push a new node to the front as:

    # Just need to add the data; does not need to concern node creation logic
    new_node = self.list.add_to_head((key, value)); # Add key+value as a tuple.

Comment on lines +69 to +90
self._move_to_head(node)
return node.value

def set(self, key, value):
node = self.map.get(key)

if node is not None:
# update existing
node.value = value
self._move_to_head(node)
return

# new key
if len(self.map) >= self.limit:
# evict least recently used (tail)
lru = self.tail
if lru is not None:
self._remove_node(lru)
del self.map[lru.key]

new_node = _Node(key, value)
self._add_to_head(new_node)
Copy link

Choose a reason for hiding this comment

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

It seems some of the properties and methods accessed here belong to LinkedList (not to LruCache).

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