cactus183/patchbench-dev
0
1from collections import OrderedDict2 3 4class LRUCache:5 def __init__(self, capacity: int):6 if capacity <= 0:7 raise ValueError("capacity must be positive")8 self.capacity = capacity9 self.cache = OrderedDict()10 11 def get(self, key):12 """Get value by key. Returns None if not found."""13 # BUG: does not move key to end (mark as recently used)14 return self.cache.get(key, None)15 16 def put(self, key, value):17 """Insert or update a key-value pair."""18 if key in self.cache:19 self.cache[key] = value20 # BUG: does not move updated key to end21 return22 if len(self.cache) >= self.capacity:23 # Evicts the first item — correct only if access order is maintained24 # But since get() doesn't reorder, this evicts based on insertion order25 self.cache.popitem(last=False)26 self.cache[key] = value27 