Grok 20.3.2
grk::MinHeap< T, IT, L > Class Template Reference

Thread-safe min-heap for values with customizable locking. More...

#include <MinHeap.h>

Inheritance diagram for grk::MinHeap< T, IT, L >:
grk::MinHeapBase< IT >

Public Member Functions

void push (const T &val)
 Pushes a value onto the heap.
std::vector< T > push_and_pop (const T &val)
 Pushes a value and pops all consecutive elements starting from 'start'.
size_t size () const
 Returns the current size of the heap.

Private Attributes

std::priority_queue< T, std::vector< T >, MinHeapComparator< T > > queue
 Underlying min-heap.

Additional Inherited Members

Protected Member Functions inherited from grk::MinHeapBase< IT >
 MinHeapBase ()
Protected Attributes inherited from grk::MinHeapBase< IT >
std::mutex queue_mutex
 Mutex for thread-safe access.
IT start
 Tracks the next expected index for sequential popping.

Detailed Description

template<typename T, typename IT, typename L>
requires HasGetIndex<T> && std::integral<IT>
class grk::MinHeap< T, IT, L >

Thread-safe min-heap for values with customizable locking.

Template Parameters
TType stored in the heap, must satisfy HasGetIndex.
ITIntegral type for indexing (e.g., int, size_t).
LLocker type (e.g., MinHeapLocker or MinHeapFakeLocker).

Member Function Documentation

◆ push()

template<typename T, typename IT, typename L>
void grk::MinHeap< T, IT, L >::push ( const T & val)
inline

Pushes a value onto the heap.

Parameters
valThe value to add.

References queue, and grk::MinHeapBase< IT >::queue_mutex.

◆ push_and_pop()

template<typename T, typename IT, typename L>
std::vector< T > grk::MinHeap< T, IT, L >::push_and_pop ( const T & val)
inline

Pushes a value and pops all consecutive elements starting from 'start'.

Parameters
valThe value to push.
Returns
Vector of popped elements in index order.

References queue, grk::MinHeapBase< IT >::queue_mutex, and grk::MinHeapBase< IT >::start.

◆ size()

template<typename T, typename IT, typename L>
size_t grk::MinHeap< T, IT, L >::size ( ) const
inline

Returns the current size of the heap.

Returns
Number of elements in the heap.

References queue, and grk::MinHeapBase< IT >::queue_mutex.

Member Data Documentation

◆ queue

template<typename T, typename IT, typename L>
std::priority_queue<T, std::vector<T>, MinHeapComparator<T> > grk::MinHeap< T, IT, L >::queue
private

Underlying min-heap.

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


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