casacore
|
#include <Queue.h>
Public Member Functions | |
Queue () | |
Create a Queue with no elements. More... | |
Queue (const Queue< T > &other) | |
Create a queue which is a copy of other. More... | |
~Queue () | |
Queue< T > & | operator= (const Queue< T > &other) |
Create a queue which is a copy of other. More... | |
void | enqueue (const T &value) |
Place an element in the queue. More... | |
void | operator() (const T &value) |
Short-hand for enqueue();. More... | |
void | dequeue (T &value) |
Remove an element from the head of the queue and decrease nelements() by one. More... | |
T | operator() () |
Short-hand for dequeue. More... | |
void | clear () |
Delete all the elements from the queue, and free up any resources. More... | |
void | compress () |
Leave this queue logically unchanged, but remove unused storage. More... | |
uInt | nelements () const |
How many elements are in the queue? More... | |
Private Attributes | |
Int | first_p |
Int | next_p |
Block< T > | data_p |
A First-In-First-Out (FIFO) data structure.
A Queue as implemented here is a simple container which can grow with time, and which returns its elements (only) in the order they are inserted. That is, the fundamental operations are to insert an element in the queue (at the "back") and retrieve an element (from the "front").
Presently the implementation is rather simple. It stores the elements in a Block<T> which resizes (exponentially to avoid quadratic behaviour) when necessary. New elements are added to the end of the block, old elements are pulled off the front of the Block. The positions at the beginning are only reclaimed when the queue is empty or the compress() member is called. This implementation is reasonably time efficient, but not necessarily space efficient. A more sophisticated implementation may be necessary eventually.
To be used in a Queue, a class must have a default constructor, assignment operator, and copy constructor.
This class was written for an application which thought it needed to queue up some Glish events while it processed other Glish events. In fact that application (Clean) was simplified so that it doesn't presently operate that way.
casacore::Queue< T >::Queue | ( | ) |
Create a Queue with no elements.
casacore::Queue< T >::Queue | ( | const Queue< T > & | other | ) |
Create a queue which is a copy of other.
Compresses unused heap storage.
casacore::Queue< T >::~Queue | ( | ) |
void casacore::Queue< T >::clear | ( | ) |
Delete all the elements from the queue, and free up any resources.
void casacore::Queue< T >::compress | ( | ) |
Leave this queue logically unchanged, but remove unused storage.
With the present Block<T> based implementation, removes the unused entries at the beginning of the block.
void casacore::Queue< T >::dequeue | ( | T & | value | ) |
Remove an element from the head of the queue and decrease nelements() by one.
If called when nelements() is zero, an exception is thrown.
void casacore::Queue< T >::enqueue | ( | const T & | value | ) |
Place an element in the queue.
After calling this, nelements() is increaed by one.
|
inline |
How many elements are in the queue?
Definition at line 136 of file Queue.h.
References casacore::Queue< T >::first_p, and casacore::Queue< T >::next_p.
T casacore::Queue< T >::operator() | ( | ) |
Short-hand for dequeue.
void casacore::Queue< T >::operator() | ( | const T & | value | ) |
Short-hand for enqueue();.
Queue<T>& casacore::Queue< T >::operator= | ( | const Queue< T > & | other | ) |
Create a queue which is a copy of other.
Compresses unused heap storage.
|
private |
|
private |
Definition at line 138 of file Queue.h.
Referenced by casacore::Queue< T >::nelements().
|
private |
Definition at line 139 of file Queue.h.
Referenced by casacore::Queue< T >::nelements().