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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef MAP_SCHEDULER_H
10#define MAP_SCHEDULER_H
11
12#include "scheduler.h"
13
14#include <map>
15#include <stdint.h>
16#include <utility>
17
18/**
19 * @file
20 * @ingroup scheduler
21 * ns3::MapScheduler declaration.
22 */
23
24namespace ns3
25{
26
27/**
28 * @ingroup scheduler
29 * @brief a std::map event scheduler
30 *
31 * This class implements the an event scheduler using an std::map
32 * data structure.
33 *
34 * @par Time Complexity
35 *
36 * Operation | Amortized %Time | Reason
37 * :----------- | :-------------- | :-----
38 * Insert() | Logarithmic | `std::map::insert()`
39 * IsEmpty() | Constant | `std::map::empty()`
40 * PeekNext() | Constant | `std::map::begin()`
41 * Remove() | Logarithmic | `std::map::find()`
42 * RemoveNext() | Constant | `std::map::begin()`
43 *
44 * @par Memory Complexity
45 *
46 * Category | Memory | Reason
47 * :-------- | :------------------------------- | :-----
48 * Overhead | 3 x `sizeof (*)` + 2 x `size_t`<br/>(40 bytes) | red-black tree
49 * Per Event | 3 x `sizeof (*)` + `int`<br/>(32 bytes) | red-black tree
50 *
51 */
52class MapScheduler : public Scheduler
53{
54 public:
55 /**
56 * Register this type.
57 * @return The object TypeId.
58 */
59 static TypeId GetTypeId();
60
61 /** Constructor. */
63 /** Destructor. */
64 ~MapScheduler() override;
65
66 // Inherited
67 void Insert(const Scheduler::Event& ev) override;
68 bool IsEmpty() const override;
69 Scheduler::Event PeekNext() const override;
71 void Remove(const Scheduler::Event& ev) override;
72
73 private:
74 /** Event list type: a Map from EventKey to EventImpl. */
75 typedef std::map<Scheduler::EventKey, EventImpl*> EventMap;
76 /** EventMap iterator. */
77 typedef std::map<Scheduler::EventKey, EventImpl*>::iterator EventMapI;
78 /** EventMap const iterator. */
79 typedef std::map<Scheduler::EventKey, EventImpl*>::const_iterator EventMapCI;
80
81 /** The event list. */
83};
84
85} // namespace ns3
86
87#endif /* MAP_SCHEDULER_H */
a std::map event scheduler
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.
std::map< Scheduler::EventKey, EventImpl * >::const_iterator EventMapCI
EventMap const iterator.
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.
EventMap m_list
The event list.
static TypeId GetTypeId()
Register this type.
~MapScheduler() override
Destructor.
Maintain the event list.
Definition scheduler.h:146
a unique identifier for an interface.
Definition type-id.h:48
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:173