diff options
author | Juan Batiz-Benet <jbenet@cs.stanford.edu> | 2011-07-10 05:52:52 -0700 |
---|---|---|
committer | Juan Batiz-Benet <jbenet@cs.stanford.edu> | 2011-07-10 05:56:02 -0700 |
commit | 9525ec85063786716ab61a57dd69f556586792d3 (patch) | |
tree | 65d71ac288b6326e5d406b11fe0c3b527756049b /pylru.py | |
parent | a96e83d7fb11c86349218eb2c22200d639665929 (diff) | |
download | pylru-9525ec85063786716ab61a57dd69f556586792d3.tar.gz |
Added keys, values, and items to allow iteration
Diffstat (limited to 'pylru.py')
-rw-r--r-- | pylru.py | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -178,7 +178,23 @@ class lrucache(object): self.mtf(node) self.head = node.next + def items(self): + # return the (key, value) pairs (from most recent to least) + # without modifying the cache order + return zip(self.keys(), self.values()) + + def keys(self): + + # return the keys (from most recent to least) in the cache + # does not modify the cache order + return self.table.keys() + + def values(self): + + # return the values in the cache (from most recent to least) + # does not modify the cache order + return [node.obj for node in self.table.values()] def size(self, size=None): @@ -324,7 +340,6 @@ class lruwrap(object): except KeyError: pass - def sync(self): if self.writeback: for key in self.dirty: |