#include <OTC/collctn/priqueue.hh> template<class T> class OTC_PriorityQueue {
public:
static os_typespec* get_os_typespec();
OTC_PriorityQueue(OTC_QueueType theType=OTCLIB_ASCENDING);
OTC_PriorityQueue(int (*theRankFn)( T const&, T const&), OTC_QueueType theType=OTCLIB_ASCENDING );
OTC_PriorityQueue(OTC_PriorityQueue<T> const& theQueue);
~OTC_PriorityQueue();
OTC_Boolean isEmpty() const;
inline u_int count() const;
T const& head() const;
void add(T const& theItem);
T remove();
void clear();
void discard(u_int theCount);
protected:
OTC_PriorityQueue<T>& operator=( OTC_PriorityQueue<T> const& theQueue );
};
OTC_RankActions
for the type that
the queue is parameterised over. For a particular instance of
the class, a function which determines the ordering, may also be
passed to the constructor.
The priority queue can be instantiated in two forms, either
as an ascending queue, or a descending queue. In an ascending
queue, a remove()
operation will remove the least ranked
item in the queue. In a descending queue, the highest ranked
item will be removed. In situations where a particular type
of queue must be ensured, the derived versions of this class
can be used. The derived classes are OTC_AscendingQueue
and
OTC_DescendingQueue
.
Note that it is the user's responsibility to deal with deletion of
objects held in the queue, when it is parameterised over a pointer
type, ie., this class works independently of the OTC_BaseActions
class.
OTC_PriorityQueue(OTC_QueueType theType=OTCLIB_ASCENDING);
theType
should be the type of queue required.
Valid types are OTCLIB_ASCENDING
and OTCLIB_DESCENDING
.
OTC_PriorityQueue(int (*theRankFn)(
T const&,
T const&),
OTC_QueueType theType=OTCLIB_ASCENDING
);
theRankFn
is a comparison function to be used
instead of OTC_RankActions
. theType
should be the type of queue required.
Valid types are OTCLIB_ASCENDING
and OTCLIB_DESCENDING
.
OTC_PriorityQueue(OTC_PriorityQueue<T> const& theQueue);
theQueue
. If the queue holds
pointers, only the pointers are copied
and not what the pointers point at.
~OTC_PriorityQueue();
OTC_Boolean isEmpty() const;
OTCLIB_TRUE
if the queue is empty.
inline u_int count() const;
T const& head() const;
void add(T const& theItem);
theItem
into the queue based.
T remove();
void clear();
void discard(u_int theCount);
theCount
items
in the queue. If the queue does not
hold that many items, an exception
is raised.
OTC_AscendingQueue
, OTC_DescendingQueue
, OTC_Queue
,
OTC_RankActions