File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments