src/simulator/heap-scheduler.h
changeset 2913 66dd24c80d75
parent 1696 0de65f4c8c43
child 3182 61fe7fe81ebd
equal deleted inserted replaced
2912:843e6218834f 2913:66dd24c80d75
       
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2005 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 SCHEDULER_HEAP_H
       
    22 #define SCHEDULER_HEAP_H
       
    23 
       
    24 #include "scheduler.h"
       
    25 #include <stdint.h>
       
    26 #include <vector>
       
    27 
       
    28 namespace ns3 {
       
    29 
       
    30 class EventHolder;
       
    31 
       
    32 class HeapScheduler : public Scheduler {
       
    33 public:
       
    34   HeapScheduler ();
       
    35   virtual ~HeapScheduler ();
       
    36 
       
    37   virtual void Insert (const EventId &id);
       
    38   virtual bool IsEmpty (void) const;
       
    39   virtual EventId PeekNext (void) const;
       
    40   virtual EventId RemoveNext (void);
       
    41   virtual bool Remove (const EventId &ev);
       
    42 
       
    43 private:
       
    44   typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
       
    45 
       
    46   inline uint32_t Parent (uint32_t id) const;
       
    47   uint32_t Sibling (uint32_t id) const;
       
    48   inline uint32_t LeftChild (uint32_t id) const;
       
    49   inline uint32_t RightChild (uint32_t id) const;
       
    50   inline uint32_t Root (void) const;
       
    51   /* Return the position in the array of the last element included in it. */
       
    52   uint32_t Last (void) const;
       
    53   inline bool IsRoot (uint32_t id) const;
       
    54   inline bool IsBottom (uint32_t id) const;
       
    55   inline bool IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const;
       
    56   inline bool IsLessStrictly (uint32_t a, uint32_t b) const;
       
    57   inline uint32_t Smallest (uint32_t a, uint32_t b) const;
       
    58 
       
    59   inline void Exch (uint32_t a, uint32_t b);
       
    60   void BottomUp (void);
       
    61   void TopDown (uint32_t start);
       
    62 
       
    63   BinaryHeap m_heap;
       
    64 };
       
    65 
       
    66 }; // namespace ns3
       
    67 
       
    68 
       
    69 #endif /* SCHEDULER_HEAP_H */