a binary heap event scheduler More...
#include <heap-scheduler.h>
Public Member Functions | |
HeapScheduler () | |
virtual | ~HeapScheduler () |
virtual void | Insert (const Event &ev) |
virtual bool | IsEmpty (void) const |
virtual Event | PeekNext (void) const |
virtual Event | RemoveNext (void) |
virtual void | Remove (const Event &ev) |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
This method returns the TypeId associated to ns3::HeapScheduler. | |
Private Types | |
typedef std::vector< Event > | BinaryHeap |
Private Member Functions | |
uint32_t | Parent (uint32_t id) const |
uint32_t | Sibling (uint32_t id) const |
uint32_t | LeftChild (uint32_t id) const |
uint32_t | RightChild (uint32_t id) const |
uint32_t | Root (void) const |
uint32_t | Last (void) const |
bool | IsRoot (uint32_t id) const |
bool | IsBottom (uint32_t id) const |
bool | IsLessStrictly (uint32_t a, uint32_t b) const |
uint32_t | Smallest (uint32_t a, uint32_t b) const |
void | Exch (uint32_t a, uint32_t b) |
void | BottomUp (void) |
void | TopDown (uint32_t start) |
Private Attributes | |
BinaryHeap | m_heap |
a binary heap event scheduler
This code started as a c++ translation of a java-based code written in 2005 to implement a heap sort. So, this binary heap is really a pretty straightforward implementation of the classic data structure. Not much to say about it.
What is smart about this code ?
Definition at line 47 of file heap-scheduler.h.
typedef std::vector<Event> ns3::HeapScheduler::BinaryHeap [private] |
Definition at line 62 of file heap-scheduler.h.
ns3::HeapScheduler::HeapScheduler | ( | ) |
Definition at line 44 of file heap-scheduler.cc.
References m_heap.
ns3::HeapScheduler::~HeapScheduler | ( | ) | [virtual] |
Definition at line 53 of file heap-scheduler.cc.
void ns3::HeapScheduler::BottomUp | ( | void | ) | [private] |
Definition at line 131 of file heap-scheduler.cc.
References Exch(), IsLessStrictly(), IsRoot(), Last(), and Parent().
Referenced by Insert().
void ns3::HeapScheduler::Exch | ( | uint32_t | a, | |
uint32_t | b | |||
) | [inline, private] |
Definition at line 103 of file heap-scheduler.cc.
References m_heap, NS_ASSERT, and NS_LOG_DEBUG.
Referenced by BottomUp(), Remove(), RemoveNext(), and TopDown().
TypeId ns3::HeapScheduler::GetTypeId | ( | void | ) | [static] |
This method returns the TypeId associated to ns3::HeapScheduler.
No Attributes defined for this type.
No TraceSources defined for this type.
Reimplemented from ns3::Scheduler.
Definition at line 35 of file heap-scheduler.cc.
References ns3::TypeId::SetParent().
void ns3::HeapScheduler::Insert | ( | const Event & | ev | ) | [virtual] |
Definition at line 178 of file heap-scheduler.cc.
References BottomUp(), and m_heap.
bool ns3::HeapScheduler::IsBottom | ( | uint32_t | id | ) | const [inline, private] |
bool ns3::HeapScheduler::IsEmpty | ( | void | ) | const [virtual] |
Implements ns3::Scheduler.
Definition at line 125 of file heap-scheduler.cc.
References m_heap.
bool ns3::HeapScheduler::IsLessStrictly | ( | uint32_t | a, | |
uint32_t | b | |||
) | const [inline, private] |
Definition at line 113 of file heap-scheduler.cc.
References m_heap.
Referenced by BottomUp(), Smallest(), and TopDown().
bool ns3::HeapScheduler::IsRoot | ( | uint32_t | id | ) | const [inline, private] |
uint32_t ns3::HeapScheduler::Last | ( | void | ) | const [private] |
Definition at line 90 of file heap-scheduler.cc.
References m_heap.
Referenced by BottomUp(), Remove(), and RemoveNext().
uint32_t ns3::HeapScheduler::LeftChild | ( | uint32_t | id | ) | const [inline, private] |
Definition at line 67 of file heap-scheduler.cc.
Referenced by TopDown().
uint32_t ns3::HeapScheduler::Parent | ( | uint32_t | id | ) | const [inline, private] |
Definition at line 57 of file heap-scheduler.cc.
Referenced by BottomUp().
Scheduler::Event ns3::HeapScheduler::PeekNext | ( | void | ) | const [virtual] |
This method cannot be invoked if the list is empty.
Implements ns3::Scheduler.
Definition at line 185 of file heap-scheduler.cc.
void ns3::HeapScheduler::Remove | ( | const Event & | ev | ) | [virtual] |
Scheduler::Event ns3::HeapScheduler::RemoveNext | ( | void | ) | [virtual] |
This method cannot be invoked if the list is empty. Remove the next earliest event from the event list.
Implements ns3::Scheduler.
Definition at line 190 of file heap-scheduler.cc.
uint32_t ns3::HeapScheduler::RightChild | ( | uint32_t | id | ) | const [inline, private] |
Definition at line 72 of file heap-scheduler.cc.
Referenced by TopDown().
uint32_t ns3::HeapScheduler::Root | ( | void | ) | const [inline, private] |
Definition at line 78 of file heap-scheduler.cc.
Referenced by IsRoot(), PeekNext(), and RemoveNext().
uint32_t ns3::HeapScheduler::Sibling | ( | uint32_t | id | ) | const [private] |
Definition at line 62 of file heap-scheduler.cc.
uint32_t ns3::HeapScheduler::Smallest | ( | uint32_t | a, | |
uint32_t | b | |||
) | const [inline, private] |
Definition at line 119 of file heap-scheduler.cc.
References IsLessStrictly().
Referenced by TopDown().
void ns3::HeapScheduler::TopDown | ( | uint32_t | start | ) | [private] |
Definition at line 143 of file heap-scheduler.cc.
References Exch(), IsBottom(), IsLessStrictly(), LeftChild(), NS_ASSERT, RightChild(), and Smallest().
Referenced by Remove(), and RemoveNext().
BinaryHeap ns3::HeapScheduler::m_heap [private] |
Definition at line 80 of file heap-scheduler.h.
Referenced by Exch(), HeapScheduler(), Insert(), IsBottom(), IsEmpty(), IsLessStrictly(), Last(), PeekNext(), Remove(), and RemoveNext().