make SchedulerHeap not use the internal iterator void *
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 11 Dec 2006 19:36:48 +0100
changeset 186 a6a7a9ae74d9
parent 185 098b789ca5e6
child 187 be0936ed7c63
make SchedulerHeap not use the internal iterator void *
src/simulator/scheduler-heap.cc
src/simulator/scheduler-heap.h
--- a/src/simulator/scheduler-heap.cc	Mon Dec 11 19:14:38 2006 +0100
+++ b/src/simulator/scheduler-heap.cc	Mon Dec 11 19:36:48 2006 +0100
@@ -63,18 +63,6 @@
 SchedulerHeap::~SchedulerHeap ()
 {}
 
-void
-SchedulerHeap::StoreInEvent (EventImpl *ev, uint32_t index) const
-{
-  long tmp = index;
-  ev->SetInternalIterator ((void *)tmp);
-}
-uint32_t
-SchedulerHeap::GetFromEvent (EventImpl *ev) const
-{
-  long tmp = (long)ev->GetInternalIterator ();
-  return (uint32_t)tmp;
-}
 uint32_t 
 SchedulerHeap::Parent (uint32_t id) const
 {
@@ -129,8 +117,6 @@
   std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
   m_heap[a] = m_heap[b];
   m_heap[b] = tmp;
-  StoreInEvent (m_heap[a].first, a);
-  StoreInEvent (m_heap[b].first, b);
 }
 
 bool
@@ -204,7 +190,6 @@
 {
   m_heap.push_back (std::make_pair (event, key));
   BottomUp ();
-  StoreInEvent (event, Last ());
   return EventId (event, key.m_ns, key.m_uid);
 }
 
@@ -230,22 +215,37 @@
 EventImpl *
 SchedulerHeap::RealRemove (EventId id, Scheduler::EventKey *key)
 {
-  EventImpl *ev = id.GetEventImpl ();
-  uint32_t i = GetFromEvent (ev);
-  *key = m_heap[i].second;
-  Exch (i, Last ());
+  Scheduler::EventKeyCompare compare;
+  uint32_t top;
+  uint32_t bottom;
+  bottom = 1;
+  top = Last ();
+  key->m_ns = id.GetNs ();
+  key->m_uid = id.GetUid ();
+  while (top != bottom)
+    {
+      uint32_t i = bottom + (top - bottom) / 2;
+      if (compare (*key, m_heap[i].second))
+        {
+          top = i;
+        }
+      else
+        {
+          bottom = i;
+        }
+    }
+  assert (top == bottom);
+  assert (m_heap[top].second.m_uid == id.GetUid ());
+  EventImpl *retval = m_heap[top].first;
+  Exch (top, Last ());
   m_heap.pop_back ();
   TopDown ();
-  return ev;
+  return retval;
 }
 
 bool 
 SchedulerHeap::RealIsValid (EventId id)
 {
-  EventImpl *ev = id.GetEventImpl ();
-  uint32_t i = GetFromEvent (ev);
-  Scheduler::EventKey key = m_heap[i].second;
-  return (key.m_ns == id.GetNs () &&
-          key.m_uid == id.GetUid ());
+  return true;
 }
 }; // namespace ns3
--- a/src/simulator/scheduler-heap.h	Mon Dec 11 19:14:38 2006 +0100
+++ b/src/simulator/scheduler-heap.h	Mon Dec 11 19:36:48 2006 +0100
@@ -45,8 +45,6 @@
   virtual bool RealIsValid (EventId id);
 
   typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
-  inline void StoreInEvent (EventImpl *ev, uint32_t index) const;
-  uint32_t GetFromEvent (EventImpl *ev) const;
 
   inline uint32_t Parent (uint32_t id) const;
   uint32_t Sibling (uint32_t id) const;