MCPcopy
hub / github.com/TheAlgorithms/Python / get

Method get

other/lru_cache.py:246–264  ·  view source on GitHub ↗

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

(self, key: T)

Source from the content-addressed store, hash-verified

244 return key in self.cache
245
246 def get(self, key: T) -> U | None:
247 """
248 Returns the value for the input key and updates the Double Linked List.
249 Returns None if key is not present in cache
250 """
251 # Note: pythonic interface would throw KeyError rather than return None
252
253 if key in self.cache:
254 self.hits += 1
255 value_node: DoubleLinkedListNode[T, U] = self.cache[key]
256 node = self.list.remove(self.cache[key])
257 assert node == value_node
258
259 # node is guaranteed not None because it is in self.cache
260 assert node is not None
261 self.list.add(node)
262 return node.val
263 self.miss += 1
264 return None
265
266 def put(self, key: T, value: U) -> None:
267 """

Callers 15

collect_datasetFunction · 0.45
create_treeFunction · 0.45
gradientMethod · 0.45
read_modelMethod · 0.45
added_solution_file_pathFunction · 0.45
length_conversionFunction · 0.45
length_conversionFunction · 0.45
covid_statsFunction · 0.45
stock_priceFunction · 0.45

Calls 2

removeMethod · 0.45
addMethod · 0.45

Tested by 1

test_instagram_userFunction · 0.36