equal
deleted
inserted
replaced
1333 |
1333 |
1334 def get(self, k, default=None): |
1334 def get(self, k, default=None): |
1335 try: |
1335 try: |
1336 return self.__getitem__(k) |
1336 return self.__getitem__(k) |
1337 except KeyError: |
1337 except KeyError: |
|
1338 return default |
|
1339 |
|
1340 def peek(self, k, default=_notset): |
|
1341 """Get the specified item without moving it to the head |
|
1342 |
|
1343 Unlike get(), this doesn't mutate the internal state. But be aware |
|
1344 that it doesn't mean peek() is thread safe. |
|
1345 """ |
|
1346 try: |
|
1347 node = self._cache[k] |
|
1348 return node.value |
|
1349 except KeyError: |
|
1350 if default is _notset: |
|
1351 raise |
1338 return default |
1352 return default |
1339 |
1353 |
1340 def clear(self): |
1354 def clear(self): |
1341 n = self._head |
1355 n = self._head |
1342 while n.key is not _notset: |
1356 while n.key is not _notset: |