scheduler.py

changeset 69
8705e296c7a0
parent 59
8d0a815022cc
child 75
2a44b9649212
--- a/scheduler.py	Fri Jan 26 00:11:47 2018 +0000
+++ b/scheduler.py	Fri Jan 26 09:27:07 2018 +0000
@@ -21,22 +21,23 @@
         raise NotImplementedError
 
     def insert_after(self, ev):
-        if not self.next:
-            ev.prev=self
-            self.next=ev
-            ev.next=None
-        elif ev<self.next:
+        if not self.next or ev<self.next:
             self.insert_immediately_after(ev)
         else:
             self.next.insert_after(ev)
 
     def insert_immediately_after(self, ev):
+        assert(ev.next is None and ev.prev is None)
         ev.prev=self
         ev.next=self.next
-        if ev.next:
-            ev.next.prev=ev
         self.next=ev
 
+    def insert_immediately_before(self, ev):
+        assert(ev.next is None and ev.prev is None)
+        ev.next=self
+        ev.prev=self.prev
+        self.prev=ev
+
     def unlink(self):
         n=self.next
         p=self.prev
@@ -74,7 +75,7 @@
         if not self._list:
             self._list=ev
         elif ev<self._list:
-            ev.insert_immediately_after(self._list)
+            self._list.insert_immediately_before(ev)
             self._list=ev
         else:
             self._list.insert_after(ev)

mercurial