other.least_recently_used

Attributes

T

lru_cache

Classes

LRUCache

Page Replacement Algorithm, Least Recently Used (LRU) Caching.

Module Contents

class other.least_recently_used.LRUCache(n: int)

Bases: Generic[T]

Page Replacement Algorithm, Least Recently Used (LRU) Caching.

>>> lru_cache: LRUCache[str | int] = LRUCache(4)
>>> lru_cache.refer("A")
>>> lru_cache.refer(2)
>>> lru_cache.refer(3)
>>> lru_cache
LRUCache(4) => [3, 2, 'A']
>>> lru_cache.refer("A")
>>> lru_cache
LRUCache(4) => ['A', 3, 2]
>>> lru_cache.refer(4)
>>> lru_cache.refer(5)
>>> lru_cache
LRUCache(4) => [5, 4, 'A', 3]
__repr__() str
display() None

Prints all the elements in the store.

refer(x: T) None

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.

_MAX_CAPACITY: int = 10
dq_store: collections.deque[T]
key_reference: set[T]
other.least_recently_used.T
other.least_recently_used.lru_cache: LRUCache[str | int]