80 template <
class ValueType,
class T=real_t>
99 void enqueue(
const ValueType& value, T priority);
107 ValueType dequeueMin();
115 std::size_t size()
const;
123 std::size_t maxSize()
const;
142 void print(std::ostream &os)
const;
154 std::multimap<T, ValueType> elems;
155 std::size_t maximumSize;
160 template <
class ValueType,
class T>
161 gsBoundedPriorityQueue<ValueType, T>::gsBoundedPriorityQueue(std::size_t maxSize)
163 maximumSize = maxSize;
168 template <
class ValueType,
class T>
169 void gsBoundedPriorityQueue<ValueType, T>::enqueue(
const ValueType& value, T priority)
172 elems.insert(std::make_pair(priority, value));
175 if (size() > maxSize()) {
176 typename std::multimap<T, ValueType>::iterator last = elems.end();
184 template <
class ValueType,
class T>
185 ValueType gsBoundedPriorityQueue<ValueType, T>::dequeueMin()
188 ValueType result = elems.begin()->second;
191 elems.erase(elems.begin());
197 template <
class ValueType,
class T>
198 std::size_t gsBoundedPriorityQueue<ValueType, T>::size()
const
203 template <
class ValueType,
class T>
204 bool gsBoundedPriorityQueue<ValueType, T>::empty()
const
206 return elems.empty();
210 template <
class ValueType,
class T>
211 std::size_t gsBoundedPriorityQueue<ValueType, T>::maxSize()
const
218 template <
class ValueType,
class T>
219 T gsBoundedPriorityQueue<ValueType, T>::best()
const
221 return empty()? std::numeric_limits<T>::infinity() : elems.begin()->first;
224 template <
class ValueType,
class T>
225 T gsBoundedPriorityQueue<ValueType, T>::worst()
const
227 return empty()? std::numeric_limits<T>::infinity() : elems.rbegin()->first;
230 template <
class ValueType,
class T>
233 os <<
"BPQ(" << size() <<
") [" << best() <<
".." << worst() <<
"].\n";
friend std::ostream & operator<<(std::ostream &os, const gsBoundedPriorityQueue &obj)
Print (as string) operator.
Definition: gsBoundedPriorityQueue.h:145
An implementation of the bounded priority queue abstraction.
Definition: gsBoundedPriorityQueue.h:81
void print(std::ostream &os) const
Prints the object as a string.
Definition: gsBoundedPriorityQueue.h:231