class Node: def __init__(self, mt, red=True): self.mt = mt self.red = red self.min_t = mt self.max_t = mt self.events = MaxHeap() self.left = None self.right = None self.count = 0 def add(self, t0, t1, dt, eid): self.events.push(dt, eid) if t0 < self.min_t: self.min_t = t0 if t1 > self.max_t: self.max_t = t1 def updateMinMax(self): self.updateMinMaxChild(self.left) self.updateMinMaxChild(self.right) def updateMinMaxChild(self, child): if child: if child.min_t < self.min_t: self.min_t = child.min_t if child.max_t > self.max_t: self.max_t = child.max_t
def cleanTimeRangeList(lst): num = len(lst) points = [] for start, end in lst: points += [ (start, False), (end, True), ] lst = [] points.sort() started_pq = MaxHeap() for cursor, isEnd in points: if isEnd: if not started_pq: raise RuntimeError('cursor=%s, lastStart=None'%cursor) start, tmp = started_pq.pop() #print('pop %s'%start) if not started_pq: lst.append((start, cursor)) else: #print('push %s'%cursor) started_pq.push(cursor, None) return lst
def cleanTimeRangeList(lst): num = len(lst) points = [] for start, end in lst: points += [ (start, False), (end, True), ] lst = [] points.sort() started_pq = MaxHeap() for cursor, isEnd in points: if isEnd: if not started_pq: raise RuntimeError('cursor=%s, lastStart=None' % cursor) start, tmp = started_pq.pop() #print('pop %s'%start) if not started_pq: lst.append((start, cursor)) else: #print('push %s'%cursor) started_pq.push(cursor, None) return lst