Ticket #32: lrucache.patch
| File lrucache.patch, 1.0 kB (added by schwa, 16 months ago) |
|---|
-
.py
old new 40 40 41 41 from __future__ import generators 42 42 import time 43 from heapq import heappush, heappop, heapify43 from ftputil_heapq import heappush, heappop, heapify 44 44 45 45 __version__ = "0.2" 46 46 __all__ = ['CacheKeyError', 'LRUCache', 'DEFAULT_SIZE'] … … 177 177 yield node.key 178 178 raise StopIteration 179 179 180 def print_heap(self): 181 for item in self.__heap: 182 print " ", item.key 183 180 184 def __setattr__(self, name, value): 181 185 object.__setattr__(self, name, value) 182 186 # automagically shrink heap on resize 183 187 if name == 'size': 184 188 while len(self.__heap) > value: 189 #print "Before heappop" 190 #self.print_heap() 185 191 lru = heappop(self.__heap) 192 #print "After heappop" 193 #print lru.key 194 #self.print_heap() 186 195 del self.__dict[lru.key] 187 196 188 197 def __repr__(self):
