BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlcc::MultipriorityQueue< TYPE > Class Template Reference

#include <bdlcc_multipriorityqueue.h>

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (MultipriorityQueue, bslma::UsesBslmaAllocator)
 
 MultipriorityQueue (bslma::Allocator *basicAllocator=0)
 
 MultipriorityQueue (int numPriorities, bslma::Allocator *basicAllocator=0)
 
 ~MultipriorityQueue ()
 
void popFront (TYPE *item, int *itemPriority=0)
 
int pushBack (const TYPE &item, int itemPriority)
 
int pushBack (bslmf::MovableRef< TYPE > item, int itemPriority)
 
void pushBackMultipleRaw (const TYPE &item, int itemPriority, int numItems)
 
void pushFrontMultipleRaw (const TYPE &item, int itemPriority, int numItems)
 
int tryPopFront (TYPE *item, int *itemPriority=0)
 
void removeAll ()
 Remove and destroy all items from this multi-priority queue.
 
void enable ()
 
void disable ()
 
int numPriorities () const
 
int length () const
 Return the total number of items in this multi-priority queue.
 
bool isEmpty () const
 
bool isEnabled () const
 

Detailed Description

template<class TYPE>
class bdlcc::MultipriorityQueue< TYPE >

This class implements a thread-enabled multipriority queue whose priorities are restricted to a (small) set of contiguous N integer values, [ 0 .. N - 1 ], with 0 being the most urgent.

This class does have a notion of value, namely the sequence of priority/element pairs, constrained to be in decreasing order of urgency (i.e., monotonically increasing priority values). However, no value-semantic operations are implemented. Note that elements having the same priority are maintained in First-In-First-Out (FIFO) order. Note that the current implementation supports up to a maximum of sizeof(int) * CHAR_BIT priorities.

This class is implemented as a set of linked lists, one for each priority. Two vectors are used to maintain head and tail pointers for the lists.

See bdlcc_multipriorityqueue

Constructor & Destructor Documentation

◆ MultipriorityQueue() [1/2]

template<class TYPE >
bdlcc::MultipriorityQueue< TYPE >::MultipriorityQueue ( bslma::Allocator basicAllocator = 0)
explicit

◆ MultipriorityQueue() [2/2]

template<class TYPE >
bdlcc::MultipriorityQueue< TYPE >::MultipriorityQueue ( int  numPriorities,
bslma::Allocator basicAllocator = 0 
)
explicit

Create a multipriority queue. Optionally specify numPriorities, the number of distinct priorities supported by the multipriority queue. If numPriorities is not specified, the (implementation-imposed maximum) number 32 is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 1 <= numPriorities <= 32 (if specified).

◆ ~MultipriorityQueue()

template<class TYPE >
bdlcc::MultipriorityQueue< TYPE >::~MultipriorityQueue ( )

Destroy this container. The behavior is undefined unless all access or modification of the container has completed prior to this call.

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

template<class TYPE >
bdlcc::MultipriorityQueue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( MultipriorityQueue< TYPE >  ,
bslma::UsesBslmaAllocator   
)

◆ disable()

template<class TYPE >
void bdlcc::MultipriorityQueue< TYPE >::disable ( )
inline

Disable pushes to this multipriority queue. This method has no effect unless the queue was enabled.

◆ enable()

template<class TYPE >
void bdlcc::MultipriorityQueue< TYPE >::enable ( )
inline

Enable pushes to this multipriority queue. This method has no effect unless the queue was disabled.

◆ isEmpty()

template<class TYPE >
bool bdlcc::MultipriorityQueue< TYPE >::isEmpty ( ) const
inline

Return true if there are no items in this multi-priority queue, and false otherwise.

◆ isEnabled()

template<class TYPE >
bool bdlcc::MultipriorityQueue< TYPE >::isEnabled ( ) const
inline

Return true if this multipriority queue is enable and false otherwise.

◆ length()

template<class TYPE >
int bdlcc::MultipriorityQueue< TYPE >::length ( ) const
inline

◆ numPriorities()

template<class TYPE >
int bdlcc::MultipriorityQueue< TYPE >::numPriorities ( ) const
inline

Return the number of distinct priorities (indicated at construction) that are supported by this multi-priority queue.

◆ popFront()

template<class TYPE >
void bdlcc::MultipriorityQueue< TYPE >::popFront ( TYPE *  item,
int *  itemPriority = 0 
)
inline

Remove the least-recently added item having the most urgent priority (lowest value) from this multi-priority queue and load its value into the specified item. If this queue is empty, this method blocks the calling thread until an item becomes available. If the optionally specified itemPriority is non-null, load the priority of the popped item into itemPriority. The behavior is undefined unless item is non-null. Note this is unaffected by the enabled / disabled state of the queue.

◆ pushBack() [1/2]

template<class TYPE >
int bdlcc::MultipriorityQueue< TYPE >::pushBack ( bslmf::MovableRef< TYPE >  item,
int  itemPriority 
)

Insert the value of the specified item with the specified itemPriority into this multipriority queue before any queued items having a less urgent priority (higher value) than itemPriority, and after any items having the same or more urgent priority (lower value) than itemPriority. item is left in a valid but unspecified state. If the multipriority queue is enabled, the push succeeds and 0 is returned, otherwise the push fails, the queue remains unchanged, and a nonzero value is returned. The behavior is undefined unless 0 <= itemPriority < numPriorities().

◆ pushBack() [2/2]

template<class TYPE >
int bdlcc::MultipriorityQueue< TYPE >::pushBack ( const TYPE &  item,
int  itemPriority 
)

Insert the value of the specified item with the specified itemPriority into this multipriority queue before any queued items having a less urgent priority (higher value) than itemPriority, and after any items having the same or more urgent priority (lower value) than itemPriority. If the multipriority queue is enabled, the push succeeds and 0 is returned, otherwise the push fails, the queue remains unchanged, and a nonzero value is returned. The behavior is undefined unless 0 <= itemPriority < numPriorities().

◆ pushBackMultipleRaw()

template<class TYPE >
void bdlcc::MultipriorityQueue< TYPE >::pushBackMultipleRaw ( const TYPE &  item,
int  itemPriority,
int  numItems 
)

Insert the value of the specified item with the specified itemPriority onto the back of this multipriority queue before any queued items having a less urgent priority (higher value) than itemPriority, and after any items having the same or more urgent priority (lower value) than itemPriority. All of the specified numItems items are pushed as a single atomic action, unless the copy constructor for one of them throws an exception, in which case a possibly empty subset of the pushes will have completed and no memory will be leaked. Raw means that the push will succeed even if the multipriority queue is disabled. Note that this method is targeted for specific use by the class bdlmt::MultipriorityThreadPool. The behavior is undefined unless 0 <= itemPriority < numPriorities().

◆ pushFrontMultipleRaw()

template<class TYPE >
void bdlcc::MultipriorityQueue< TYPE >::pushFrontMultipleRaw ( const TYPE &  item,
int  itemPriority,
int  numItems 
)

Insert the value of the specified item with the specified itemPriority into the front of this multipriority queue the specified numItems times, before any queued items having the same or less urgent priority (higher value) than itemPriority, and after any items having more urgent priority (lower value) than itemPriority. All numItems items are pushed as a single atomic action, unless the copy constructor throws while creating one of them, in which case a possibly empty subset of the pushes will have completed and no memory will be leaked. Raw means that the push will succeed even if the multipriority queue is disabled. The behavior is undefined unless 0 <= itemPriority < numPriorities(). Note that this method is targeted at specific uses by the class bdlmt::MultipriorityThreadPool.

◆ removeAll()

template<class TYPE >
void bdlcc::MultipriorityQueue< TYPE >::removeAll ( )

◆ tryPopFront()

template<class TYPE >
int bdlcc::MultipriorityQueue< TYPE >::tryPopFront ( TYPE *  item,
int *  itemPriority = 0 
)
inline

Attempt to remove (immediately) the least-recently added item having the most urgent priority (lowest value) from this multi-priority queue. On success, load the value of the popped item into the specified item; if the optionally specified itemPriority is non-null, load the priority of the popped item into itemPriority; and return 0. Otherwise, leave item and itemPriority unmodified, and return a non-zero value indicating that this queue was empty. The behavior is undefined unless item is non-null. Note this is unaffected by the enabled / disabled state of the queue.


The documentation for this class was generated from the following file: