@@ -10,7 +10,7 @@ class LRUCache(dict):
10
10
Initialize an LRU Cache with given capacity.
11
11
capacity : int -> the capacity of the LRU Cache
12
12
'''
13
- def __init__ (self , capacity : int ):
13
+ def __init__ (self , capacity : int )-> None :
14
14
self .remaining :int = capacity
15
15
16
16
'''
@@ -36,8 +36,15 @@ def get(self, key:Hashable)->Any:
36
36
This method puts the value associated with the key provided inside of the LRU cache.
37
37
key : Hashable -> a hashable object that is mapped to a value inside of the LRU cache.
38
38
value: Any -> any object that is to be associated with the key inside of the LRU cache.
39
+ >>> cache = LRUCache(2)
40
+ >>> cache.put(3,3)
41
+ >>> cache
42
+ {3:3}
43
+ >>> cache.put(2,2)
44
+ >>> cache
45
+ {3:3, 2:2}
39
46
'''
40
- def put (self , key :Hashable , value :Any ):
47
+ def put (self , key :Hashable , value :Any )-> None :
41
48
# To pop the last value inside of the LRU cache
42
49
if key in self :
43
50
self .pop (key )
@@ -49,7 +56,7 @@ def put(self, key:Hashable, value:Any):
49
56
else : self .pop (next (iter (self )))
50
57
self [key ] = value
51
58
52
- def main ():
59
+ def main ()-> None :
53
60
'''Example test case with LRU_Cache of size 2'''
54
61
cache = LRUCache (2 ) # Creates an LRU cache with size 2
55
62
cache .put (1 ,1 ) # cache = {1:1}
0 commit comments