Grok 20.3.2
grk::SimpleHeap< T > Class Template Reference

A simple non-thread-safe min-heap for tracking contiguous sequences of size_t indices. More...

#include <MinHeap.h>

Public Member Functions

void push (T index)
 Pushes an index onto the heap.
std::optional< T > push_and_pop (T index)
 Pushes an index and returns the greatest integer at the end of the contiguous sequence.
size_t size () const
 Returns the current size of the heap.

Private Attributes

std::priority_queue< T, std::vector< T >, std::greater< T > > queue
 Min-heap of indices.
start = 0
 Tracks the next expected index in the sequence.

Detailed Description

template<typename T>
class grk::SimpleHeap< T >

A simple non-thread-safe min-heap for tracking contiguous sequences of size_t indices.

Member Function Documentation

◆ push()

template<typename T>
void grk::SimpleHeap< T >::push ( T index)
inline

Pushes an index onto the heap.

Parameters
indexThe index to add.

References queue.

◆ push_and_pop()

template<typename T>
std::optional< T > grk::SimpleHeap< T >::push_and_pop ( T index)
inline

Pushes an index and returns the greatest integer at the end of the contiguous sequence.

Parameters
indexThe index to push.
Returns
The greatest consecutive index in the sequence starting from the initial start, or std::nullopt if no contiguous sequence exists.

References queue, and start.

◆ size()

template<typename T>
size_t grk::SimpleHeap< T >::size ( ) const
inline

Returns the current size of the heap.

Returns
Number of indices in the heap.

References queue.

Member Data Documentation

◆ queue

template<typename T>
std::priority_queue<T, std::vector<T>, std::greater<T> > grk::SimpleHeap< T >::queue
private

Min-heap of indices.

Referenced by push(), push_and_pop(), and size().

◆ start

template<typename T>
T grk::SimpleHeap< T >::start = 0
private

Tracks the next expected index in the sequence.

Referenced by push_and_pop().


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