SPFVertex Priority Queue
This commit is contained in:
@@ -49,7 +49,6 @@ SPFVertex::Initialize ()
|
||||
// XXX previous = 0
|
||||
}
|
||||
|
||||
|
||||
StaticRouteManagerLSDB::~StaticRouteManagerLSDB()
|
||||
{
|
||||
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB ()");
|
||||
@@ -401,6 +400,28 @@ StaticRouteManagerTest::RunTests (void)
|
||||
{
|
||||
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
|
||||
//
|
||||
|
||||
@@ -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 @@ public:
|
||||
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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user