SPFVertex Priority Queue
authorCraig Dowell <craigdo@ee.washington.edu>
Tue, 10 Jul 2007 17:35:44 -0700
changeset 1068 019229673fb4
parent 1067 704eb2583865
child 1069 5a396452fe65
SPFVertex Priority Queue
src/routing/static-route-manager.cc
src/routing/static-route-manager.h
--- a/src/routing/static-route-manager.cc	Tue Jul 10 15:03:39 2007 -0700
+++ b/src/routing/static-route-manager.cc	Tue Jul 10 17:35:44 2007 -0700
@@ -49,7 +49,6 @@
   // XXX previous = 0
 }
 
-
 StaticRouteManagerLSDB::~StaticRouteManagerLSDB()
 {
   NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB ()");
@@ -401,6 +400,28 @@
 {
   bool ok = true;
 
+  SPFVertexPriorityQueue candidate;     // <----------------
+
+  for (int i = 0; i < 100; ++i)
+    {
+      SPFVertex *v = new SPFVertex;
+      v->m_distanceFromRoot = rand () % 100;
+      candidate.push (v);               // <----------------
+    }
+
+  uint32_t lastDistance = 0;
+
+  for (int i = 0; i < 100; ++i)
+    {
+      SPFVertex *v = candidate.top ();  // <----------------
+      candidate.pop ();                 // <----------------
+      if (v->m_distanceFromRoot < lastDistance)
+        {
+          ok = false;
+        }
+      lastDistance = v->m_distanceFromRoot;
+    }
+
   // Build fake link state database; four routers (0-3), 3 point-to-point
   // links
   //
--- a/src/routing/static-route-manager.h	Tue Jul 10 15:03:39 2007 -0700
+++ b/src/routing/static-route-manager.h	Tue Jul 10 17:35:44 2007 -0700
@@ -18,6 +18,7 @@
 
 #include <stdint.h>
 #include <list>
+#include <queue>
 #include <map>
 #include "ns3/object.h"
 #include "ns3/ptr.h"
@@ -58,8 +59,20 @@
   uint32_t m_distanceFromRoot;
 
   bool m_stat;  // true if LSA is in SPF tree already
+
+  struct Greater : public std::binary_function< SPFVertex*, SPFVertex*, bool>
+  {
+    bool operator()(const SPFVertex *v1, const SPFVertex *v2) const
+    {
+      return v1->m_distanceFromRoot > v2->m_distanceFromRoot;
+    }
+  };
 };
 
+typedef std::vector<SPFVertex*> SPFVector_t;
+typedef std::priority_queue<SPFVertex*, SPFVector_t, SPFVertex::Greater> 
+  SPFVertexPriorityQueue;
+
 /**
  * \brief The Link State DataBase (LSDB) of a static router
  */