• Main Page
  • Classes
  • Files
  • File List

ScheduledEventsQueue.h

00001 #ifndef ScheduledEventsQueue_H_
00002 #define ScheduledEventsQueue_H_
00003 
00004 #include "globals.h"
00005 
00006 #include <iostream>
00007 using std::cout;
00008 using std::endl;
00009 
00010 #include <list>
00011 using std::list;
00012 
00013 #include <vector>
00014 using std::vector;
00015 
00016 #include <queue>
00017 using std::priority_queue;
00018 
00019 #include <assert.h>
00020 
00021 
00023 class ScheduledEventsQueue
00024 {
00025 
00026 public:
00027 
00029     /* \param chunkSize Constant used for internal memory management.
00030      *                   Should increase with increasing
00031      *                   expected number of spikes.
00032      */
00033     ScheduledEventsQueue(int chunkSize = EVENT_BUFFER_CHUNK_SIZE );
00034 
00036     virtual ~ScheduledEventsQueue();
00037 
00039 
00044     void scheduleEvent(event_target_group_id_t etg, Time t);
00045 
00047         struct Node
00048         {
00049                 event_target_group_id_t etg;
00050                 Time time;
00051                 Node *next;
00052         };
00053 
00054         class NodeCompare {
00055         public:
00056                 bool operator()(Node const * left, Node const * right) const {
00057                         return left->time > right->time;
00058                 }
00059         };
00060 
00061     inline Node * top();
00062 
00063     Time topTime();
00064 
00065     inline void pop();
00066 
00067 
00069     void reset();
00070 
00071 
00073     bool empty() const {
00074         return event_queue.empty();
00075     }
00076 
00077 protected:
00078 
00080     void init();
00081 
00082     priority_queue<Node*, vector<Node*>, NodeCompare > event_queue;
00083 
00085     Node *getFreeNode(void);
00086 
00088     vector< Node* > chunkBuffer;
00089 
00091     Node *currentFreeChunk;
00092 
00094     int  nextFreeNodeIdx;
00095 
00097     size_t nextFreeChunkIdx;
00098 
00100     Node* recycledNodes;
00101 
00103     int chunkSize;
00104 
00105     double fillitup[32];
00106 };
00107 
00108 inline ScheduledEventsQueue::Node * ScheduledEventsQueue::top()
00109 {
00110         return event_queue.top();
00111 }
00112 
00113 inline Time ScheduledEventsQueue::topTime()
00114 {
00115         return event_queue.top()->time;
00116 }
00117 
00118 
00119 inline void ScheduledEventsQueue::pop()
00120 {
00121         Node *n = event_queue.top();
00122         n->next = recycledNodes;
00123         recycledNodes = n;
00124         event_queue.pop();
00125 }
00126 
00127 inline void ScheduledEventsQueue::scheduleEvent(event_target_group_id_t etg, Time t)
00128 {
00129         Node *n = getFreeNode();
00130         n->etg = etg;
00131         n->time = t;
00132         event_queue.push(n);
00133 }
00134 
00135 
00136 
00137 #endif /*ScheduledEventsQueue_H_*/

Generated on Wed Sep 18 2013 11:25:40 for NEVESIM by  doxygen 1.7.1