The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt > Class Template Reference

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.
 

Detailed Description

template<class DataT, class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
class sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >

A data structure that allows pushing/emplacing into it with a given sorter.

Template Parameters
DataTThe data to be contained and sorted
SortingAlgorithmTThe sorting algorithm to use
bounded_cntThe 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.

Member Typedef Documentation

◆ const_iterator

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
using sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::const_iterator = typename PQueueType::const_iterator

Definition at line 69 of file PriorityQueue.hpp.

◆ iterator

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
using sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::iterator = typename PQueueType::iterator

Definition at line 68 of file PriorityQueue.hpp.

◆ size_type

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
using sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::size_type = size_t

Definition at line 67 of file PriorityQueue.hpp.

Constructor & Destructor Documentation

◆ PriorityQueue() [1/2]

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::PriorityQueue ( )
inline

Create a priority queue with a default instance of the sorting algorithm.

Definition at line 75 of file PriorityQueue.hpp.

◆ PriorityQueue() [2/2]

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::PriorityQueue ( const SortingAlgorithmT &  sort_alg)
inline

Create a priority queue with a specific instance of the sorting algorithm.

Parameters
sort_algReference to the sorting algorithm instance

Definition at line 84 of file PriorityQueue.hpp.

Member Function Documentation

◆ back()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
const DataT & sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::back ( ) const
inline

Get the last element (lowest priority) in the queue.

Definition at line 124 of file PriorityQueue.hpp.

Here is the call graph for this function:

◆ clear()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
void sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::clear ( )
inline

Clear the entire queue.

Definition at line 136 of file PriorityQueue.hpp.

◆ empty()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
bool sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::empty ( ) const
inline

Is the queue empty?

Definition at line 113 of file PriorityQueue.hpp.

◆ erase()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
void sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::erase ( const const_iterator &  it)
inline

Erase the item from the queue (const_iterator/iterator)

Definition at line 146 of file PriorityQueue.hpp.

◆ forceFront()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
void sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::forceFront ( const DataT &  data)
inline

Force a data entry to the front of the queue.

Parameters
dataReference 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.

◆ insert()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
void sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::insert ( const DataT &  data)
inline

Inserts the data item into the list using the sorting alg. Stops at the first insertion.

Parameters
dataThe data to insert

Definition at line 94 of file PriorityQueue.hpp.

◆ pop()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
void sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::pop ( )
inline

Pop the front of the queue (highest priority)

Definition at line 130 of file PriorityQueue.hpp.

Here is the call graph for this function:

◆ remove()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
void sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::remove ( const DataT &  data)
inline

Remove the item from the queue.

Definition at line 141 of file PriorityQueue.hpp.

◆ size()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
size_t sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::size ( ) const
inline

Get the number of items in the queue.

Definition at line 108 of file PriorityQueue.hpp.

◆ top()

template<class DataT , class SortingAlgorithmT = std::less<DataT>, size_t bounded_cnt = 0>
const DataT & sparta::PriorityQueue< DataT, SortingAlgorithmT, bounded_cnt >::top ( ) const
inline

Get the first element in the queue.

Definition at line 118 of file PriorityQueue.hpp.

Here is the call graph for this function:

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