A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
map-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 MAP_SCHEDULER_H
21#define MAP_SCHEDULER_H
22
23#include "scheduler.h"
24
25#include <map>
26#include <stdint.h>
27#include <utility>
28
29/**
30 * \file
31 * \ingroup scheduler
32 * ns3::MapScheduler declaration.
33 */
34
35namespace ns3
36{
37
38/**
39 * \ingroup scheduler
40 * \brief a std::map event scheduler
41 *
42 * This class implements the an event scheduler using an std::map
43 * data structure.
44 *
45 * \par Time Complexity
46 *
47 * Operation | Amortized %Time | Reason
48 * :----------- | :-------------- | :-----
49 * Insert() | Logarithmic | `std::map::insert()`
50 * IsEmpty() | Constant | `std::map::empty()`
51 * PeekNext() | Constant | `std::map::begin()`
52 * Remove() | Logarithmic | `std::map::find()`
53 * RemoveNext() | Constant | `std::map::begin()`
54 *
55 * \par Memory Complexity
56 *
57 * Category | Memory | Reason
58 * :-------- | :------------------------------- | :-----
59 * Overhead | 3 x `sizeof (*)` + 2 x `size_t`<br/>(40 bytes) | red-black tree
60 * Per Event | 3 x `sizeof (*)` + `int`<br/>(32 bytes) | red-black tree
61 *
62 */
63class MapScheduler : public Scheduler
64{
65 public:
66 /**
67 * Register this type.
68 * \return The object TypeId.
69 */
70 static TypeId GetTypeId();
71
72 /** Constructor. */
74 /** Destructor. */
75 ~MapScheduler() override;
76
77 // Inherited
78 void Insert(const Scheduler::Event& ev) override;
79 bool IsEmpty() const override;
80 Scheduler::Event PeekNext() const override;
82 void Remove(const Scheduler::Event& ev) override;
83
84 private:
85 /** Event list type: a Map from EventKey to EventImpl. */
86 typedef std::map<Scheduler::EventKey, EventImpl*> EventMap;
87 /** EventMap iterator. */
88 typedef std::map<Scheduler::EventKey, EventImpl*>::iterator EventMapI;
89 /** EventMap const iterator. */
90 typedef std::map<Scheduler::EventKey, EventImpl*>::const_iterator EventMapCI;
91
92 /** The event list. */
94};
95
96} // namespace ns3
97
98#endif /* MAP_SCHEDULER_H */
a std::map event scheduler
Definition: map-scheduler.h:64
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
MapScheduler()
Constructor.
std::map< Scheduler::EventKey, EventImpl * > EventMap
Event list type: a Map from EventKey to EventImpl.
Definition: map-scheduler.h:86
std::map< Scheduler::EventKey, EventImpl * >::const_iterator EventMapCI
EventMap const iterator.
Definition: map-scheduler.h:90
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
bool IsEmpty() const override
Test if the schedule is empty.
std::map< Scheduler::EventKey, EventImpl * >::iterator EventMapI
EventMap iterator.
Definition: map-scheduler.h:88
EventMap m_list
The event list.
Definition: map-scheduler.h:93
static TypeId GetTypeId()
Register this type.
~MapScheduler() override
Destructor.
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