A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
heap-scheduler.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#ifndef HEAP_SCHEDULER_H
21#define HEAP_SCHEDULER_H
22
23#include "scheduler.h"
24
25#include <stdint.h>
26#include <vector>
27
34namespace ns3
35{
36
74{
75 public:
80 static TypeId GetTypeId();
81
85 ~HeapScheduler() override;
86
87 // Inherited
88 void Insert(const Scheduler::Event& ev) override;
89 bool IsEmpty() const override;
90 Scheduler::Event PeekNext() const override;
92 void Remove(const Scheduler::Event& ev) override;
93
94 private:
96 typedef std::vector<Scheduler::Event> BinaryHeap;
97
104 inline std::size_t Parent(std::size_t id) const;
111 std::size_t Sibling(std::size_t id) const;
118 inline std::size_t LeftChild(std::size_t id) const;
125 inline std::size_t RightChild(std::size_t id) const;
131 inline std::size_t Root() const;
136 std::size_t Last() const;
143 inline bool IsRoot(std::size_t id) const;
150 inline bool IsBottom(std::size_t id) const;
158 inline bool IsLessStrictly(std::size_t a, std::size_t b) const;
166 inline std::size_t Smallest(std::size_t a, std::size_t b) const;
173 inline void Exch(std::size_t a, std::size_t b);
175 void BottomUp();
181 void TopDown(std::size_t start);
182
185};
186
187} // namespace ns3
188
189#endif /* HEAP_SCHEDULER_H */
a binary heap event scheduler
std::size_t Root() const
Get the root index of the heap.
void TopDown(std::size_t start)
Percolate a deletion bubble down the heap.
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
~HeapScheduler() override
Destructor.
static TypeId GetTypeId()
Register this type.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
bool IsLessStrictly(std::size_t a, std::size_t b) const
Compare (less than) two items.
HeapScheduler()
Constructor.
std::size_t RightChild(std::size_t id) const
Get the right child index of a given entry.
BinaryHeap m_heap
The event list.
bool IsRoot(std::size_t id) const
Test if an index is the root.
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
std::vector< Scheduler::Event > BinaryHeap
Event list type: vector of Events, managed as a heap.
void Exch(std::size_t a, std::size_t b)
Swap two items.
std::size_t Smallest(std::size_t a, std::size_t b) const
Minimum of two items.
std::size_t Sibling(std::size_t id) const
Get the next sibling of a given entry.
std::size_t Parent(std::size_t id) const
Get the parent index of a given entry.
bool IsBottom(std::size_t id) const
Test if an index is at the bottom of the heap.
std::size_t LeftChild(std::size_t id) const
Get the left child of a given entry.
void BottomUp()
Percolate a newly inserted Last item to its proper position.
std::size_t Last() const
Return the index of the last element.
bool IsEmpty() const override
Test if the schedule is empty.
Maintain the event list.
Definition: scheduler.h:157
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
Scheduler event.
Definition: scheduler.h:184