The Sparta Modeling Framework
|
A data structure that allows pushing/emplacing into it with a given sorter. More...
#include <PriorityQueue.hpp>
Public Types | |
using | size_type = size_t |
using | iterator = typename PQueueType::iterator |
using | const_iterator = typename PQueueType::const_iterator |
Public Member Functions | |
PriorityQueue () | |
Create a priority queue with a default instance of the sorting algorithm. | |
PriorityQueue (const SortingAlgorithmT &sort_alg) | |
Create a priority queue with a specific instance of the sorting algorithm. | |
void | insert (const DataT &data) |
Inserts the data item into the list using the sorting alg. Stops at the first insertion. | |
size_t | size () const |
Get the number of items in the queue. | |
bool | empty () const |
Is the queue empty? | |
const DataT & | top () const |
Get the first element in the queue. | |
const DataT & | back () const |
Get the last element (lowest priority) in the queue. | |
void | pop () |
Pop the front of the queue (highest priority) | |
void | clear () |
Clear the entire queue. | |
void | remove (const DataT &data) |
Remove the item from the queue. | |
void | erase (const const_iterator &it) |
Erase the item from the queue (const_iterator/iterator) | |
void | forceFront (const DataT &data) |
Force a data entry to the front of the queue. | |
iterator | begin () |
Iterator to beginning of the queue – highest priority. | |
const_iterator | begin () const |
Const Iterator to beginning of the queue – highest priority. | |
iterator | end () |
Iterator to end of the queue – end priority. | |
const_iterator | end () const |
Const Iterator to end of the queue – end priority. | |
A data structure that allows pushing/emplacing into it with a given sorter.
DataT | The data to be contained and sorted |
SortingAlgorithmT | The sorting algorithm to use |
bounded_cnt | The max number of elements in this PriorityQueue |
The PriorityQueue can be used by picking algorithms in a model where more than one entry of a block is ready (for whatever reason) and the model needs to know which one to "pick" for the next operation.
The queue defines a less-than type of sorter by default, but allows the modeler to define an operator object that can override the behavior.
In addition, entries in the queue can be removed (even in the middle). This is handy for items in the queue that are no longer participating in the priority.
Finally, the queue supports a basic override to the order, allowing a "high priority" DataT object to be pushed to the front, even if that object doesn't conform to the ordering rules.
If the template parameter bounded_cnt is non-zero, the PriorityQueue will be bounded to an upper limit of bounded_cnt. This also improves the performance of the PriorityQueue (uses sparta::utils::FastList).
Definition at line 56 of file PriorityQueue.hpp.
using sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::const_iterator = typename PQueueType::const_iterator |
Definition at line 69 of file PriorityQueue.hpp.
using sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::iterator = typename PQueueType::iterator |
Definition at line 68 of file PriorityQueue.hpp.
using sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::size_type = size_t |
Definition at line 67 of file PriorityQueue.hpp.
|
inline |
Create a priority queue with a default instance of the sorting algorithm.
Definition at line 75 of file PriorityQueue.hpp.
|
inline |
Create a priority queue with a specific instance of the sorting algorithm.
sort_alg | Reference to the sorting algorithm instance |
Definition at line 84 of file PriorityQueue.hpp.
|
inline |
Get the last element (lowest priority) in the queue.
Definition at line 124 of file PriorityQueue.hpp.
|
inline |
Clear the entire queue.
Definition at line 136 of file PriorityQueue.hpp.
|
inline |
Is the queue empty?
Definition at line 113 of file PriorityQueue.hpp.
|
inline |
Erase the item from the queue (const_iterator/iterator)
Definition at line 146 of file PriorityQueue.hpp.
|
inline |
Force a data entry to the front of the queue.
data | Reference to the data object forced to the front of the queue |
Push the data item to the front of the queue, bypassing the internal sorting algorithm. This is handy if multiple items from multiple directions should be prioritized, but a last-minute item, which normally is a low-priority item, must be handled immediately.
Definition at line 161 of file PriorityQueue.hpp.
|
inline |
Inserts the data item into the list using the sorting alg. Stops at the first insertion.
data | The data to insert |
Definition at line 94 of file PriorityQueue.hpp.
|
inline |
Pop the front of the queue (highest priority)
Definition at line 130 of file PriorityQueue.hpp.
|
inline |
Remove the item from the queue.
Definition at line 141 of file PriorityQueue.hpp.
|
inline |
Get the number of items in the queue.
Definition at line 108 of file PriorityQueue.hpp.
|
inline |
Get the first element in the queue.
Definition at line 118 of file PriorityQueue.hpp.