| Home | Trees | Indices | Help |
|
|---|
|
|
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 #
4 # This file is part of logilab-common.
5 #
6 # logilab-common is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation, either version 2.1 of the License, or (at your option) any
9 # later version.
10 #
11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License along
17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>.
18 """Prioritized tasks queue
19
20 :organization: Logilab
21
22
23 """
24 __docformat__ = "restructuredtext en"
25
26 from bisect import insort_left
27 from Queue import Queue
28
29 LOW = 0
30 MEDIUM = 10
31 HIGH = 100
32
33 REVERSE_PRIORITY = {
34 0: 'LOW',
35 10: 'MEDIUM',
36 100: 'HIGH'
37 }
38
39
41
43 """Initialize the queue representation"""
44 self.maxsize = maxsize
45 # ordered list of task, from the lowest to the highest priority
46 self.queue = []
47
49 """Put a new item in the queue"""
50 for i, task in enumerate(self.queue):
51 # equivalent task
52 if task == item:
53 # if new task has a higher priority, remove the one already
54 # queued so the new priority will be considered
55 if task < item:
56 item.merge(task)
57 del self.queue[i]
58 break
59 # else keep it so current order is kept
60 task.merge(item)
61 return
62 insort_left(self.queue, item)
63
67
70
79
98
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Jun 11 21:52:21 2010 | http://epydoc.sourceforge.net |