dotPriorityQueue.py (1636B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dotWeapons\common\dotPriorityQueue.py 2 import heapq 3 4 class DotPriorityQueue(object): 5 _REMOVED = '<removed-dot>' 6 7 def __init__(self): 8 self._queue = [] 9 self._entries = {} 10 11 def Add(self, dotApplication): 12 applicationID = dotApplication.id 13 queueEntry = self._entries.get(applicationID) 14 if queueEntry: 15 return 16 queueEntry = QueueEntry((dotApplication.expiryTime, dotApplication)) 17 heapq.heappush(self._queue, queueEntry) 18 self._entries[applicationID] = queueEntry 19 20 def Remove(self, applicationID): 21 entry = self._entries.pop(applicationID, None) 22 if entry is None: 23 return 24 entry.dotApplication = self._REMOVED 25 26 def ExpireDotApplications(self, now): 27 while self._queue: 28 expiryTime, dotApplication = self._queue[0] 29 if dotApplication is self._REMOVED: 30 heapq.heappop(self._queue) 31 elif expiryTime <= now: 32 heapq.heappop(self._queue) 33 del self._entries[dotApplication.id] 34 else: 35 return 36 37 def IterateDotApplications(self): 38 for entry in self._entries.itervalues(): 39 yield entry.dotApplication 40 41 def IsEmpty(self): 42 return not bool(self._entries) 43 44 45 class QueueEntry(list): 46 47 @property 48 def expiryTime(self): 49 return self[0] 50 51 @property 52 def dotApplication(self): 53 return self[1] 54 55 @dotApplication.setter 56 def dotApplication(self, value): 57 self[1] = value