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