src/simulator/scheduler-heap.cc
changeset 25 9b3bb088c560
parent 16 99e833adbb46
child 36 e622fb7a8262
--- a/src/simulator/scheduler-heap.cc	Sat Sep 02 19:50:19 2006 +0200
+++ b/src/simulator/scheduler-heap.cc	Sun Sep 03 12:24:04 2006 +0200
@@ -33,7 +33,7 @@
  */
 
 #include "scheduler-heap.h"
-#include "event.h"
+#include "event-impl.h"
 #include <cassert>
 
 #define noTRACE_HEAP 1
@@ -57,25 +57,22 @@
 	// the array to make sure the indexes in the
 	// array start at one.
 	Scheduler::EventKey empty_key = {0,0};
-	m_heap.push_back (std::make_pair ((Event )0, empty_key));
+	m_heap.push_back (std::make_pair (static_cast<EventImpl *>(0), empty_key));
 }
 
 SchedulerHeap::~SchedulerHeap ()
 {}
 
- 
-void 
-SchedulerHeap::store_in_event (Event ev, uint32_t index) const
+void
+SchedulerHeap::store_in_event (EventImpl *ev, uint32_t index) const
 {
-	ev.set_tag ((void *)index);
+	ev->set_internal_iterator ((void *)index);
 }
-uint32_t 
-SchedulerHeap::get_from_event (Event const ev) const
+uint32_t
+SchedulerHeap::get_from_event (EventImpl *ev) const
 {
- 	return (uint32_t)ev.get_tag ();
+       return (uint32_t)ev->get_internal_iterator ();
 }
-
-
 uint32_t 
 SchedulerHeap::parent (uint32_t id) const
 {
@@ -127,14 +124,9 @@
 {
 	assert (b < m_heap.size () && a < m_heap.size ());
 	TRACE ("exch " << a << ", " << b);
-#if 1
-	std::swap (m_heap[a].second, m_heap[b].second);
-	std::swap (m_heap[a].first.m_impl, m_heap[b].first.m_impl);
-#else
-	std::pair<Event , Scheduler::EventKey> tmp (m_heap[a]);
+	std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
 	m_heap[a] = m_heap[b];
 	m_heap[b] = tmp;
-#endif
 	store_in_event (m_heap[a].first, a);
 	store_in_event (m_heap[b].first, b);
 }
@@ -199,16 +191,16 @@
 }
 
 
-Event  
-SchedulerHeap::insert (Event event, Scheduler::EventKey key)
+EventId
+SchedulerHeap::insert (EventImpl *event, Scheduler::EventKey key)
 {
 	m_heap.push_back (std::make_pair (event, key));
+	bottom_up ();
 	store_in_event (event, last ());
-	bottom_up ();
-	return event;
+	return EventId (event, key.m_time, key.m_uid);
 }
 
-Event
+EventImpl *
 SchedulerHeap::peek_next (void) const
 {
 	assert (!is_empty ());
@@ -229,15 +221,26 @@
 	top_down ();
 }
 
-Scheduler::EventKey
-SchedulerHeap::remove (Event const ev)
+
+EventImpl *
+SchedulerHeap::remove (EventId id, Scheduler::EventKey *key)
 {
+	EventImpl *ev = id.get_event_impl ();
 	uint32_t i = get_from_event (ev);
-	EventKey key = m_heap[i].second;
+	*key = m_heap[i].second;
 	exch (i, last ());
 	m_heap.pop_back ();
 	top_down ();
-	return key;
+	return ev;
 }
 
+bool 
+SchedulerHeap::is_valid (EventId id)
+{
+	EventImpl *ev = id.get_event_impl ();
+	uint32_t i = get_from_event (ev);
+	Scheduler::EventKey key = m_heap[i].second;
+	return (key.m_time == id.get_time () &&
+		key.m_uid == id.get_uid ());
+}
 }; // namespace ns3