Skip to content

Commit 0ae8f6e

Browse files
author
Alexander Smishlajev
committed
added class PrioList (patch from rfe [SF#413165])
1 parent 6044f9f commit 0ae8f6e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

roundup/support.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,38 @@ def ensureParentsExist(dest):
2424
if not os.path.exists(os.path.dirname(dest)):
2525
os.makedirs(os.path.dirname(dest))
2626

27+
class PrioList:
28+
'''Manages a sorted list.
29+
30+
Currently only implements method 'append' and iteration from a
31+
full list interface.
32+
Implementation: We manage a "sorted" status and sort on demand.
33+
Appending to the list will require re-sorting before use.
34+
>>> p = PrioList ()
35+
>>> for i in 5,7,1,-1 :
36+
... p.append (i)
37+
...
38+
>>> for k in p :
39+
... print k
40+
...
41+
-1
42+
1
43+
5
44+
7
45+
46+
'''
47+
def __init__(self):
48+
self.list = []
49+
self.sorted = True
50+
51+
def append(self, item):
52+
self.list.append (item)
53+
self.sorted = False
54+
55+
def __iter__(self):
56+
if not self.sorted :
57+
self.list.sort ()
58+
self.sorted = True
59+
return iter (self.list)
60+
2761
# vim: set et sts=4 sw=4 :

0 commit comments

Comments
 (0)