##// END OF EJS Templates
util: make capacity a public attribute on lrucachedict...
Gregory Szorc -
r39600:5d75a3c1 default
parent child Browse files
Show More
@@ -1241,7 +1241,7 b' class lrucachedict(object):'
1241 head.prev = head
1241 head.prev = head
1242 head.next = head
1242 head.next = head
1243 self._size = 1
1243 self._size = 1
1244 self._capacity = max
1244 self.capacity = max
1245
1245
1246 def __len__(self):
1246 def __len__(self):
1247 return len(self._cache)
1247 return len(self._cache)
@@ -1269,7 +1269,7 b' class lrucachedict(object):'
1269 self._movetohead(node)
1269 self._movetohead(node)
1270 return
1270 return
1271
1271
1272 if self._size < self._capacity:
1272 if self._size < self.capacity:
1273 node = self._addcapacity()
1273 node = self._addcapacity()
1274 else:
1274 else:
1275 # Grab the last/oldest item.
1275 # Grab the last/oldest item.
@@ -1312,7 +1312,7 b' class lrucachedict(object):'
1312 self._cache.clear()
1312 self._cache.clear()
1313
1313
1314 def copy(self):
1314 def copy(self):
1315 result = lrucachedict(self._capacity)
1315 result = lrucachedict(self.capacity)
1316
1316
1317 # We copy entries by iterating in oldest-to-newest order so the copy
1317 # We copy entries by iterating in oldest-to-newest order so the copy
1318 # has the correct ordering.
1318 # has the correct ordering.
@@ -11,6 +11,7 b' from mercurial import ('
11 class testlrucachedict(unittest.TestCase):
11 class testlrucachedict(unittest.TestCase):
12 def testsimple(self):
12 def testsimple(self):
13 d = util.lrucachedict(4)
13 d = util.lrucachedict(4)
14 self.assertEqual(d.capacity, 4)
14 d['a'] = 'va'
15 d['a'] = 'va'
15 d['b'] = 'vb'
16 d['b'] = 'vb'
16 d['c'] = 'vc'
17 d['c'] = 'vc'
General Comments 0
You need to be logged in to leave comments. Login now