Beispiel #1
0
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
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
Beispiel #3
0
 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
Beispiel #4
0
 def add(self, t0, t1, eid, debug=False):
     if debug:
         from time import strftime, localtime
         f = "%F, %T"
         print("EventSearchTree.add: %s\t%s\t%s" % (
             eid,
             strftime(f, localtime(t0)),
             strftime(f, localtime(t1)),
         ))
     ###
     if t0 == t1:
         t1 += epsTm  ## needed? FIXME
     mt = (t0 + t1) / 2.0
     dt = (t1 - t0) / 2.0
     ###
     try:
         self.root = self.addStep(
             self.root,
             t0,
             t1,
             mt,
             dt,
             eid,
         )
     except:
         myRaise()
     hp = self.byId.get(eid)
     if hp is None:
         hp = self.byId[eid] = MaxHeap()
     hp.push(mt, dt)  ## FIXME
 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
Beispiel #6
0
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
Beispiel #7
0
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