22
33from collections .abc import Callable
44
5-
65class DoubleLinkedListNode [T , U ]:
76 """
87 Double Linked List Node built specifically for LRU Cache
@@ -218,12 +217,12 @@ def __repr__(self) -> str:
218217 Return the details for the cache instance
219218 [hits, misses, capacity, current_size]
220219 """
221-
222220 return (
223221 f"CacheInfo(hits={ self .hits } , misses={ self .miss } , "
224222 f"capacity={ self .capacity } , current size={ self .num_keys } )"
225223 )
226- def __contains__ (self , key : T ) -> bool :
224+
225+ def __contains__ (self , key : T ) -> bool :
227226 """
228227 >>> cache = LRUCache(1)
229228
@@ -235,9 +234,7 @@ def __contains__(self, key: T) -> bool:
235234 >>> 1 in cache
236235 True
237236 """
238-
239237 return key in self .cache
240-
241238 def get (self , key : T ) -> U | None :
242239 """
243240 Returns the value for the input key and updates the Double Linked List.
@@ -262,7 +259,6 @@ def put(self, key: T, value: U) -> None:
262259 """
263260 Sets the value for the input key and updates the Double Linked List
264261 """
265-
266262 if key not in self .cache :
267263 if self .num_keys >= self .capacity :
268264 # delete first node (oldest) when over capacity
@@ -281,7 +277,6 @@ def put(self, key: T, value: U) -> None:
281277 self .cache [key ] = DoubleLinkedListNode (key , value )
282278 self .list .add (self .cache [key ])
283279 self .num_keys += 1
284-
285280 else :
286281 # bump node to the end of the list, update value
287282 node = self .list .remove (self .cache [key ])
@@ -314,7 +309,6 @@ def cache_decorator_wrapper(*args: T) -> U:
314309 result = func (* args )
315310 decorator_function_to_instance_map [func ].put (args [0 ], result )
316311 return result
317-
318312 def cache_info () -> LRUCache [T , U ]:
319313 return decorator_function_to_instance_map [func ]
320314
0 commit comments