sincerely
Singaporean
If you have not done so, read this full tutorial on how to use SGEXTN to build an application.
(no source file, everything inside header)
template ‹typename T, typename Comparator› class SGLPriorityQueue;
part of SGEXTN module SG_Containers
priority queue for any data type
list of all including inherited members
preprocessor file inclusion directive: #include ‹SGLPriorityQueue.h›
CMake target for BuildLah: SGEXTN::SG_Containers
see this link for more information about BuildLah
parent class: (none)
children classes: (none)
[[nodiscard]] int length() const;
void pop();
void push(const T& x);
void reserve(int newMemoryLength);
[[nodiscard]] const T& top() const;
SGLPriorityQueue provides a template based priority queue for any data type. It is guaranteed that the element in front is always the last element in the list if all priority queue elements are placed into a list and that list is sorted. This is a template based class with no separate source file. This class is a SGEXTN container. Copy constructor, copy assignment, move constructor, move assignment, and destructor work as expected. A deep copy is performed whenever this class is copied, and the new instance will not be linked to the old instance in any way. It is assumed that the contents placed into this SGEXTN container can be copied and moved. This means that their copy constructor copy assignment, move constructor, move assignment, and destructor work as expected. If this is not the case or if you want the container to store references or constant references, store pointers instead.
SGLPriorityQueue internally uses a maximum heap implemented over a resizable C array buffer. The C array buffer expands to double its size when filled.
Creates an empty priority queue.
Returns the length of the SGLPriorityQueue, which is the number of elements currently stored inside it.
Removes the most in front element of the SGLPriorityQueue.
This function has truly logarithmic time complexity.
This function does not return the first element before removing it. To access the element being removed, use SGLPriorityQueue::top before removal.
Removing from an empty SGLPriorityQueue will crash.
Inserts x into the SGLPriorityQueue.
This function has a amortised logarithmic time complexity due to the memory buffer resizing. To achieve true logarithmic time complexity, use SGLPriorityQueue::reserve to pre allocate the memory you need.
Pre allocates memory sufficient for newMemoryLength elements to be stored in the SGLPriorityQueue without resizing the memory buffer.
Nothing is done if the memory buffer is already enough to store newMemoryLength elements.
Returns the first element of the SGLPriorityQueue.
Using this when the priority queue is empty will crash.
©2025 05524F.sg (Singapore)