MCPcopy Create free account
hub / github.com/digego/extempore / PriorityQueue

Class PriorityQueue

include/PriorityQueue.h:61–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59
60 template<typename KEY, typename T>
61 class PriorityQueue {
62 typedef std::multimap< KEY, T, SortCriteria<KEY> > CONTAINER;
63 typedef typename std::multimap< KEY, T, SortCriteria<KEY> >::iterator CIter;
64
65 public:
66
67 PriorityQueue() : mutex("priority_queue")
68 {
69 mutex.init();
70 }
71
72 ~PriorityQueue()
73 {
74 mutex.destroy();
75 }
76
77 CONTAINER& getQueue() { return this->queue; }
78 CIter begin() { return queue.begin(); }
79 CIter end() { return queue.end(); }
80 CIter lower_bound(const KEY time) { return queue.lower_bound(time); }
81 CIter upper_bound(const KEY time) { return queue.upper_bound(time); }
82
83 void lock()
84 {
85 mutex.lock();
86 }
87
88 void unlock()
89 {
90 mutex.unlock();
91 }
92
93 bool add(T val)
94 {
95 mutex.lock();
96
97 CIter pos = queue.insert(std::make_pair(val->getStartTime(),val));
98
99#ifdef _DEBUG_QUEUE_
100 std::cout << "QUEUE[" << this << "] " << "Successfully Added Task. Size: " << queue.size() << " at startime " << val->getStartTime() << std::endl;
101 std::cout << "QUEUE[" << this << "] " << "Inserted as element " << (std::distance(queue.begin(),pos) + 1) << " in queue of size " << queue.size() << std::endl;
102
103 /*
104 std::cout << "-----------START----------" << std::endl;
105 pos = queue.begin();
106 CIter end = queue.end();
107 for( ;pos != end; ++pos) {
108 std::cout << pos->second->getStartTime() << std::endl;
109 }
110 std::cout << "------------END-----------" << std::endl;
111 */
112#endif
113 mutex.unlock();
114
115 return true;
116 }
117
118 int erase(std::string label)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected