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)
| 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 | """ |
no test coverage detected