A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
calendar-scheduler.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef CALENDAR_SCHEDULER_H
22 #define CALENDAR_SCHEDULER_H
23 
24 #include "scheduler.h"
25 #include <stdint.h>
26 #include <list>
27 
28 namespace ns3 {
29 
30 class EventImpl;
31 
48 {
49 public:
50  static TypeId GetTypeId (void);
51 
53  virtual ~CalendarScheduler ();
54 
55  virtual void Insert (const Event &ev);
56  virtual bool IsEmpty (void) const;
57  virtual Event PeekNext (void) const;
58  virtual Event RemoveNext (void);
59  virtual void Remove (const Event &ev);
60 
61 private:
62  void ResizeUp (void);
63  void ResizeDown (void);
64  void Resize (uint32_t newSize);
65  uint32_t CalculateNewWidth (void);
66  void Init (uint32_t nBuckets,
67  uint64_t width,
68  uint64_t startPrio);
69  inline uint32_t Hash (uint64_t key) const;
70  void PrintInfo (void);
71  void DoResize (uint32_t newSize, uint32_t newWidth);
73  void DoInsert (const Event &ev);
74 
75  typedef std::list<Scheduler::Event> Bucket;
77  // number of buckets in array
78  uint32_t m_nBuckets;
79  // duration of a bucket
80  uint64_t m_width;
81  // bucket index from which the last event was dequeued
82  uint32_t m_lastBucket;
83  // priority at the top of the bucket from which last event was dequeued
84  uint64_t m_bucketTop;
85  // the priority of the last event removed
86  uint64_t m_lastPrio;
87  // number of events in queue
88  uint32_t m_qSize;
89 };
90 
91 } // namespace ns3
92 
93 #endif /* CALENDAR_SCHEDULER_H */
uint32_t CalculateNewWidth(void)
void DoInsert(const Event &ev)
virtual Event PeekNext(void) const
virtual bool IsEmpty(void) const
virtual void Remove(const Event &ev)
void Init(uint32_t nBuckets, uint64_t width, uint64_t startPrio)
Maintain the event list.
Definition: scheduler.h:58
void Resize(uint32_t newSize)
virtual Event RemoveNext(void)
This method cannot be invoked if the list is empty.
Scheduler::Event DoRemoveNext(void)
void DoResize(uint32_t newSize, uint32_t newWidth)
std::list< Scheduler::Event > Bucket
static TypeId GetTypeId(void)
a calendar queue event scheduler
uint32_t Hash(uint64_t key) const
virtual void Insert(const Event &ev)
a unique identifier for an interface.
Definition: type-id.h:49