EventCollector: tune the parameters and add a shrinking heuristic.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 30 Jul 2007 14:48:56 +0100
changeset 1728 190372a33951
parent 1727 064aaa84c103
child 1729 8588a386e6b3
child 1737 e72c130c3a59
EventCollector: tune the parameters and add a shrinking heuristic.
src/simulator/event-collector.cc
src/simulator/event-collector.h
--- a/src/simulator/event-collector.cc	Mon Jul 30 14:22:12 2007 +0100
+++ b/src/simulator/event-collector.cc	Mon Jul 30 14:48:56 2007 +0100
@@ -19,10 +19,9 @@
  * Author: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt>
  */
 #include "event-collector.h"
-#include <algorithm>
 
 #define CLEANUP_CHUNK_MIN_SIZE 8
-#define CLEANUP_CHUNK_MAX_SIZE 1024
+#define CLEANUP_CHUNK_MAX_SIZE 128
 
 
 namespace ns3 {
@@ -46,6 +45,21 @@
   return event.IsExpired ();
 }
 
+void
+EventCollector::Grow ()
+{
+  m_nextCleanupSize += (m_nextCleanupSize < CLEANUP_CHUNK_MAX_SIZE?
+                        m_nextCleanupSize : CLEANUP_CHUNK_MAX_SIZE);
+}
+
+void
+EventCollector::Shrink ()
+{
+  while (m_nextCleanupSize > m_events.size ())
+    m_nextCleanupSize >>= 1;
+  Grow ();
+}
+
 // Called when a new event was added and the cleanup limit was exceeded in consequence.
 void
 EventCollector::Cleanup ()
@@ -54,8 +68,9 @@
 
   // If after cleanup we are still over the limit, increase the limit.
   if (m_events.size () >= m_nextCleanupSize)
-    m_nextCleanupSize = std::min (std::list<EventId>::size_type (CLEANUP_CHUNK_MAX_SIZE),
-                                  m_nextCleanupSize<<1);
+    Grow ();
+  else
+    Shrink ();
 }
 
 
--- a/src/simulator/event-collector.h	Mon Jul 30 14:22:12 2007 +0100
+++ b/src/simulator/event-collector.h	Mon Jul 30 14:48:56 2007 +0100
@@ -53,6 +53,8 @@
   std::list<EventId> m_events;
 
   void Cleanup ();
+  void Grow ();
+  void Shrink ();
 };
 
 }; // namespace ns3