@@ -54,11 +54,12 @@ def add(self, node: DoubleLinkedListNode[T, U]) -> None:
5454 previous = self .rear .prev
5555 if previous is None :
5656 raise ValueError ("Invalid list state: rear.prev is None" )
57-
57+
5858 previous .next = node
5959 node .prev = previous
6060 self .rear .prev = node
6161 node .next = self .rear
62+
6263 def remove (
6364 self , node : DoubleLinkedListNode [T , U ]
6465 ) -> Optional [DoubleLinkedListNode [T , U ]]:
@@ -108,6 +109,7 @@ def get(self, key: T) -> Optional[U]:
108109 return node .val
109110 self .miss += 1
110111 return None
112+
111113 def put (self , key : T , value : U ) -> None :
112114 """Sets the value for the input key"""
113115 if key in self .cache :
@@ -136,6 +138,7 @@ def decorator(
136138 cls , size : int = 128
137139 ) -> Callable [[Callable [..., U ]], Callable [..., U ]]:
138140 """Decorator version of LRU Cache"""
141+
139142 def decorator_func (func : Callable [..., U ]) -> Callable [..., U ]:
140143 cache_instance = cls (size )
141144
@@ -147,6 +150,7 @@ def wrapper(*args: T, **kwargs: T) -> U:
147150 result = func (* args , ** kwargs )
148151 cache_instance .put (key , result )
149152 return result
153+
150154 def cache_info () -> LRUCache :
151155 return cache_instance
152156
@@ -158,4 +162,5 @@ def cache_info() -> LRUCache:
158162
159163if __name__ == "__main__" :
160164 import doctest
165+
161166 doctest .testmod ()
0 commit comments