MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / refer

Method refer

other/least_recently_used.py:50–64  ·  view source on GitHub ↗

Looks for a page in the cache store and adds reference to the set. Remove the least recently used key if the store is full. Update store to reflect recent access.

(self, x: T)

Source from the content-addressed store, hash-verified

48 LRUCache._MAX_CAPACITY = n
49
50 def refer(self, x: T) -> None:
51 """
52 Looks for a page in the cache store and adds reference to the set.
53 Remove the least recently used key if the store is full.
54 Update store to reflect recent access.
55 """
56 if x not in self.key_reference:
57 if len(self.dq_store) == LRUCache._MAX_CAPACITY:
58 last_element = self.dq_store.pop()
59 self.key_reference.remove(last_element)
60 else:
61 self.dq_store.remove(x)
62
63 self.dq_store.appendleft(x)
64 self.key_reference.add(x)
65
66 def display(self) -> None:
67 """

Callers 1

Calls 4

appendleftMethod · 0.80
popMethod · 0.45
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected