Changeset 785:7515d06b2284


Ignore:
Timestamp:
Apr 30, 2009, 10:59:47 PM (12 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Convert:
svn:778c30c8-61e0-0310-89d4-fe2f97a467b2/trunk@836
Message:
Made test cache smaller.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lrucache.py

    r784 r785  
    110110            return cmp(self.atime, other.atime)
    111111
    112         def __repr__(self):
    113             return "Node %s => %s" % (self.key, self.obj)
    114 #             return "<%s %s => %s (%s)>" % \
    115 #                    (self.__class__, self.key, self.obj, \
    116 #                     time.asctime(time.localtime(self.atime)))
    117112
    118113    def __init__(self, size=DEFAULT_SIZE):
     
    126121        self.__dict = {}
    127122        self.size = size
    128         """Maximum size of the cache.
    129         If more than 'size' elements are added to the cache,
    130         the least-recently-used ones will be discarded."""
    131123
    132124    def __len__(self):
     
    171163            return node.obj
    172164
    173     def __iter__(self):
    174         copy = self.__heap[:]
    175         while len(copy) > 0:
    176             node = heappop(copy)
    177             yield node.key
    178         raise StopIteration
    179 
    180165    def __setattr__(self, name, value):
    181166        object.__setattr__(self, name, value)
     
    185170                lru = heappop(self.__heap)
    186171                del self.__dict[lru.key]
    187 
    188     def __repr__(self):
    189         return "<%s (%d elements)>" % (str(self.__class__), len(self.__heap))
    190172
    191173    def mtime(self, key):
     
    200182
    201183if __name__ == "__main__":
    202     cache = LRUCache(25)
    203     for i in range(30):
     184    cache = LRUCache(15)
     185    for i in range(20):
    204186        cache[i] = str(i)
    205     if 26 in cache:
    206         del cache[26]
     187    if 16 in cache:
     188        del cache[16]
    207189    # traceback occurs in this assignment
    208     cache.size = 10
     190    cache.size = 5
Note: See TracChangeset for help on using the changeset viewer.