Method
put
(self, key: int, value: int)
Source from the content-addressed store, hash-verified
| 31 | return -1 |
| 32 | |
| 33 | def put(self, key: int, value: int) -> None: |
| 34 | if key in self.cache: |
| 35 | self.remove(self.cache[key]) |
| 36 | self.cache[key] = Node(key, value) |
| 37 | self.insert(self.cache[key]) |
| 38 | |
| 39 | if len(self.cache) > self.cap: |
| 40 | # remove from the list and delete the LRU from hashmap |
| 41 | lru = self.left.next |
| 42 | self.remove(lru) |
| 43 | del self.cache[lru.key] |
Callers
nothing calls this directly
Tested by
no test coverage detected