You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pyutil/cache.py
+49-32Lines changed: 49 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -42,43 +42,50 @@ def __init__(self, c):
42
42
self.i=c.d[c.hs][2]
43
43
def__iter__(self):
44
44
returnself
45
-
defnext(self):
45
+
def__next__(self):
46
46
ifself.iisself.c.ts:
47
47
raiseStopIteration()
48
48
k=self.i
49
-
precondition(self.c.d.has_key(k), "The iterated LRUCache doesn't have the next key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", k, self.c)
49
+
precondition(kinself.c.d, "The iterated LRUCache doesn't have the next key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", k, self.c)
50
50
(v, p, n,) =self.c.d[k]
51
51
self.i=n
52
52
return (k, v,)
53
+
defnext(self):
54
+
returnself.__next__()
53
55
54
56
classKeyIterator:
55
57
def__init__(self, c):
56
58
self.c=c
57
59
self.i=c.d[c.hs][2]
58
60
def__iter__(self):
59
61
returnself
60
-
defnext(self):
62
+
def__next__(self):
61
63
ifself.iisself.c.ts:
62
64
raiseStopIteration()
63
65
k=self.i
64
-
precondition(self.c.d.has_key(k), "The iterated LRUCache doesn't have the next key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", k, self.c)
66
+
precondition(kinself.c.d, "The iterated LRUCache doesn't have the next key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", k, self.c)
65
67
(v, p, n,) =self.c.d[k]
66
68
self.i=n
67
69
returnk
70
+
defnext(self):
71
+
returnself.__next__()
68
72
69
73
classValIterator:
70
74
def__init__(self, c):
71
75
self.c=c
72
76
self.i=c.d[c.hs][2]
73
77
def__iter__(self):
74
78
returnself
75
-
defnext(self):
79
+
def__next__(self):
76
80
ifself.iisself.c.ts:
77
81
raiseStopIteration()
78
-
precondition(self.c.d.has_key(self.i), "The iterated LRUCache doesn't have the next key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c)
82
+
precondition(self.iinself.c.d, "The iterated LRUCache doesn't have the next key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c)
79
83
(v, p, n,) =self.c.d[self.i]
80
84
self.i=n
81
85
returnv
86
+
defnext(self):
87
+
returnself.__next__()
88
+
82
89
83
90
classSentinel:
84
91
def__init__(self, msg):
@@ -124,7 +131,7 @@ def _assert_invariants(self):
124
131
_assert((len(self.d) >2) == (self.d[self.hs][2] isnotself.ts) == (self.d[self.ts][1] isnotself.hs), "Head and tail point to something other than each other if and only if there is at least one element in the dictionary.", self.hs, self.ts, len(self.d))
125
132
foundprevsentinel=0
126
133
foundnextsentinel=0
127
-
for (k, (v, p, n,)) inself.d.iteritems():
134
+
for (k, (v, p, n,)) inself.d.items():
128
135
_assert(vnotin (self.hs, self.ts,))
129
136
_assert(pisnotself.ts, "A reference to the tail sentinel may not appear in prev.", k, v, p, n)
130
137
_assert(nisnotself.hs, "A reference to the head sentinel may not appear in next.", k, v, p, n)
_assert(False, "Internal error -- this should never have happened since the while loop should have terminated first.")
283
290
returnself
284
291
285
-
for (k, v,) inotherdict.iteritems():
292
+
for (k, v,) inotherdict.items():
286
293
assertself._assert_invariants()
287
294
self[k] =v
288
295
assertself._assert_invariants()
@@ -401,10 +408,10 @@ def __iter__(self):
401
408
returnself
402
409
defnext(self):
403
410
precondition(self.i<=len(self.c._lru), "The iterated SmallLRUCache doesn't have this many elements. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c)
404
-
precondition(dict.has_key(self.c, self.c._lru[self.i]), "The iterated SmallLRUCache doesn't have this key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c._lru[self.i], self.c)
405
411
ifself.i==len(self.c._lru):
406
412
raiseStopIteration()
407
-
k=self.i
413
+
precondition(dict.__contains__(self.c, self.c._lru[self.i]), "The iterated SmallLRUCache doesn't have this key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c._lru[self.i], self.c)
414
+
k=self.c._lru[self.i]
408
415
self.i+=1
409
416
return (k, dict.__getitem__(self.c, k),)
410
417
@@ -416,10 +423,10 @@ def __iter__(self):
416
423
returnself
417
424
defnext(self):
418
425
precondition(self.i<=len(self.c._lru), "The iterated SmallLRUCache doesn't have this many elements. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c)
419
-
precondition(dict.has_key(self.c, self.c._lru[self.i]), "The iterated SmallLRUCache doesn't have this key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c._lru[self.i], self.c)
420
426
ifself.i==len(self.c._lru):
421
427
raiseStopIteration()
422
-
k=self.i
428
+
precondition(dict.__contains__(self.c, self.c._lru[self.i]), "The iterated SmallLRUCache doesn't have this key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c._lru[self.i], self.c)
429
+
k=self.c._lru[self.i]
423
430
self.i+=1
424
431
returnk
425
432
@@ -431,27 +438,28 @@ def __iter__(self):
431
438
returnself
432
439
defnext(self):
433
440
precondition(self.i<=len(self.c._lru), "The iterated SmallLRUCache doesn't have this many elements. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c)
434
-
precondition(dict.has_key(self.c, self.c._lru[self.i]), "The iterated SmallLRUCache doesn't have this key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c._lru[self.i], self.c)
435
441
ifself.i==len(self.c._lru):
436
442
raiseStopIteration()
437
-
k=self.i
443
+
precondition(dict.__contains__(self.c, self.c._lru[self.i]), "The iterated SmallLRUCache doesn't have this key. Most likely this is because someone altered the contents of the LRUCache while the iteration was in progress.", self.i, self.c._lru[self.i], self.c)
_assert(len(self._lru) <=self._maxsize, "Size is required to be <= maxsize.")
453
-
_assert(len(filter(lambdax: dict.has_key(self, x), self._lru))==len(self._lru), "Each key in self._lru is required to be in dict.", filter(lambdax: notdict.has_key(self, x), self._lru), len(self._lru), self._lru, len(self), self)
454
-
_assert(len(filter(lambdax: xinself._lru, self.keys()))==len(self), "Each key in dict is required to be in self._lru.", filter(lambdax: xnotinself._lru, self.keys()), len(self._lru), self._lru, len(self), self)
461
+
_assert(len([xforxinself._lruifdict.__contains__(self, x)])==len(self._lru), "Each key in self._lru is required to be in dict.", filter(lambdax: notdict.__contains__(self, x), self._lru), len(self._lru), self._lru, len(self), self)
462
+
_assert(len([xforxinself.keys() ifxinself._lru])==len(self), "Each key in dict is required to be in self._lru.", [xforxinself.keys() ifxnotinself._lru], len(self._lru), self._lru, len(self), self)
0 commit comments