Statistics
| Branch: | Revision:

mobicen / util / EventScheduler.py @ e1cf8bea

History | View | Annotate | Download (767 Bytes)

1
import heapq
2

    
3
class EventScheduler:
4
        def __init__(self):
5
                self.queue = []
6
                self.time = 0
7
                self.last = 0
8
                self._step = 0
9

    
10
        def schedule_event(self, interval, e):
11
                t = self.time + interval
12
                if t > self.last:
13
                    self.last = t
14
                heapq.heappush(self.queue, (t, e))
15

    
16
        def pop_event(self):
17
                e = heapq.heappop(self.queue)
18
                self._step = e[0] - self.time
19
                self.time = e[0]
20
                return e[1]
21

    
22
        def elapsed_time(self):
23
                return self.time
24

    
25
        def last_event_time(self):
26
                return self.last
27

    
28
        def step(self):
29
            return self._step