MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / get

Method get

other/lfu_cache.py:232–249  ·  view source on GitHub ↗

Returns the value for the input key and updates the Double Linked List. Returns Returns None if key is not present in cache

(self, key: T)

Source from the content-addressed store, hash-verified

230 return key in self.cache
231
232 def get(self, key: T) -> U | None:
233 """
234 Returns the value for the input key and updates the Double Linked List. Returns
235 Returns None if key is not present in cache
236 """
237
238 if key in self.cache:
239 self.hits += 1
240 value_node: DoubleLinkedListNode[T, U] = self.cache[key]
241 node = self.list.remove(self.cache[key])
242 assert node == value_node
243
244 # node is guaranteed not None because it is in self.cache
245 assert node is not None
246 self.list.add(node)
247 return node.val
248 self.miss += 1
249 return None
250
251 def put(self, key: T, value: U) -> None:
252 """

Callers 1

Calls 2

removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected