A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
priority-queue-scheduler.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 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 PRIORITY_QUEUE_SCHEDULER_H
21#define PRIORITY_QUEUE_SCHEDULER_H
22
23#include "scheduler.h"
24
25#include <algorithm>
26#include <functional>
27#include <queue>
28#include <stdint.h>
29#include <utility>
30
31/**
32 * \file
33 * \ingroup scheduler
34 * Declaration of ns3::PriorityQueueScheduler class.
35 */
36
37namespace ns3
38{
39
40/**
41 * \ingroup scheduler
42 * \brief a std::priority_queue event scheduler
43 *
44 * This class implements an event scheduler using
45 * `std::priority_queue` on a `std::vector`.
46 *
47 * \par Time Complexity
48 *
49 * Operation | Amortized %Time | Reason
50 * :----------- | :--------------- | :-----
51 * Insert() | Logarithmic | `std::push_heap()`
52 * IsEmpty() | Constant | `std::vector::empty()`
53 * PeekNext() | Constant | `std::vector::front()`
54 * Remove() | Linear | `std::find()` and `std::make_heap()`
55 * RemoveNext() | Logarithmic | `std::pop_heap()`
56 *
57 * \par Memory Complexity
58 *
59 * Category | Memory | Reason
60 * :-------- | :------------------------------- | :-----
61 * Overhead | 3 x `sizeof (*)`<br/>(24 bytes) | `std::vector`
62 * Per Event | 0 | Events stored in `std::vector` directly
63 *
64 */
66{
67 public:
68 /**
69 * Register this type.
70 * \return The object TypeId.
71 */
72 static TypeId GetTypeId();
73
74 /** Constructor. */
76 /** Destructor. */
77 ~PriorityQueueScheduler() override;
78
79 // Inherited
80 void Insert(const Scheduler::Event& ev) override;
81 bool IsEmpty() const override;
82 Scheduler::Event PeekNext() const override;
84 void Remove(const Scheduler::Event& ev) override;
85
86 private:
87 /**
88 * Custom priority_queue which supports remove,
89 * and returns entries in _increasing_ time order.
90 */
91 class EventPriorityQueue : public std::priority_queue<Scheduler::Event,
92 std::vector<Scheduler::Event>,
93 std::greater<>>
94 {
95 public:
96 /**
97 * \copydoc PriorityQueueScheduler::Remove()
98 * \returns \c true if the event was found, false otherwise.
99 */
100 bool remove(const Scheduler::Event& ev);
101
102 }; // class EventPriorityQueue
103
104 /** The event queue. */
106
107}; // class PriorityQueueScheduler
108
109} // namespace ns3
110
111#endif /* PRIORITY_QUEUE_SCHEDULER_H */
Custom priority_queue which supports remove, and returns entries in increasing time order.
bool remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
a std::priority_queue event scheduler
static TypeId GetTypeId()
Register this type.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
~PriorityQueueScheduler() override
Destructor.
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
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.
EventPriorityQueue m_queue
The event queue.
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