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;
160template <
class ValueType,
class T>
161gsBoundedPriorityQueue<ValueType, T>::gsBoundedPriorityQueue(std::size_t maxSize)
163maximumSize = maxSize;
168template <
class ValueType,
class T>
169void gsBoundedPriorityQueue<ValueType, T>::enqueue(
const ValueType& value, T priority)
172elems.insert(std::make_pair(priority, value));
175if (size() > maxSize()) {
176typename std::multimap<T, ValueType>::iterator last = elems.end();
184template <
class ValueType,
class T>
185ValueType gsBoundedPriorityQueue<ValueType, T>::dequeueMin()
188ValueType result = elems.begin()->second;
191elems.erase(elems.begin());
197template <
class ValueType,
class T>
198std::size_t gsBoundedPriorityQueue<ValueType, T>::size()
const
203template <
class ValueType,
class T>
204bool gsBoundedPriorityQueue<ValueType, T>::empty()
const
210template <
class ValueType,
class T>
211std::size_t gsBoundedPriorityQueue<ValueType, T>::maxSize()
const
218template <
class ValueType,
class T>
219T gsBoundedPriorityQueue<ValueType, T>::best()
const
221return empty()? std::numeric_limits<T>::infinity() : elems.begin()->first;
224template <
class ValueType,
class T>
225T gsBoundedPriorityQueue<ValueType, T>::worst()
const
227return empty()? std::numeric_limits<T>::infinity() : elems.rbegin()->first;
230template <
class ValueType,
class T>
233 os <<
"BPQ(" << size() <<
") [" << best() <<
".." << worst() <<
"].\n";
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
friend std::ostream & operator<<(std::ostream &os, const gsBoundedPriorityQueue &obj)
Print (as string) operator.
Definition gsBoundedPriorityQueue.h:145
The G+Smo namespace, containing all definitions for the library.