src/simulator/scheduler-heap.h
changeset 150 663120712cd9
parent 131 f4fb87e77034
child 186 a6a7a9ae74d9
equal deleted inserted replaced
149:d5b12472c5e2 150:663120712cd9
     1 /* -*- Mode:NS3; -*- */
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     2 /*
     3  * Copyright (c) 2005 INRIA
     3  * Copyright (c) 2005 INRIA
     4  * All rights reserved.
     4  * All rights reserved.
     5  *
     5  *
     6  * This program is free software; you can redistribute it and/or modify
     6  * This program is free software; you can redistribute it and/or modify
    30 
    30 
    31 class EventHolder;
    31 class EventHolder;
    32 
    32 
    33 class SchedulerHeap : public Scheduler {
    33 class SchedulerHeap : public Scheduler {
    34 public:
    34 public:
    35     SchedulerHeap ();
    35   SchedulerHeap ();
    36     virtual ~SchedulerHeap ();
    36   virtual ~SchedulerHeap ();
    37 
    37 
    38 private:
    38 private:
    39     virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
    39   virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
    40     virtual bool RealIsEmpty (void) const;
    40   virtual bool RealIsEmpty (void) const;
    41     virtual EventImpl *RealPeekNext (void) const;
    41   virtual EventImpl *RealPeekNext (void) const;
    42     virtual Scheduler::EventKey RealPeekNextKey (void) const;
    42   virtual Scheduler::EventKey RealPeekNextKey (void) const;
    43     virtual void RealRemoveNext (void);
    43   virtual void RealRemoveNext (void);
    44     virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
    44   virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
    45     virtual bool RealIsValid (EventId id);
    45   virtual bool RealIsValid (EventId id);
    46 
    46 
    47     typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
    47   typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
    48     inline void StoreInEvent (EventImpl *ev, uint32_t index) const;
    48   inline void StoreInEvent (EventImpl *ev, uint32_t index) const;
    49     uint32_t GetFromEvent (EventImpl *ev) const;
    49   uint32_t GetFromEvent (EventImpl *ev) const;
    50 
    50 
    51     inline uint32_t Parent (uint32_t id) const;
    51   inline uint32_t Parent (uint32_t id) const;
    52     uint32_t Sibling (uint32_t id) const;
    52   uint32_t Sibling (uint32_t id) const;
    53     inline uint32_t LeftChild (uint32_t id) const;
    53   inline uint32_t LeftChild (uint32_t id) const;
    54     inline uint32_t RightChild (uint32_t id) const;
    54   inline uint32_t RightChild (uint32_t id) const;
    55     inline uint32_t Root (void) const;
    55   inline uint32_t Root (void) const;
    56     uint32_t Last (void) const;
    56   uint32_t Last (void) const;
    57     inline bool IsRoot (uint32_t id) const;
    57   inline bool IsRoot (uint32_t id) const;
    58     inline bool IsBottom (uint32_t id) const;
    58   inline bool IsBottom (uint32_t id) const;
    59     inline bool IsLess (uint32_t a, uint32_t b);
    59   inline bool IsLess (uint32_t a, uint32_t b);
    60     inline uint32_t Smallest (uint32_t a, uint32_t b);
    60   inline uint32_t Smallest (uint32_t a, uint32_t b);
    61 
    61 
    62     inline void Exch (uint32_t a, uint32_t b);
    62   inline void Exch (uint32_t a, uint32_t b);
    63     void BottomUp (void);
    63   void BottomUp (void);
    64     void TopDown (void);
    64   void TopDown (void);
    65 
    65 
    66     BinaryHeap m_heap;
    66   BinaryHeap m_heap;
    67 };
    67 };
    68 
    68 
    69 }; // namespace ns3
    69 }; // namespace ns3
    70 
    70 
    71 
    71