SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Heap< T, isMinHeap > Class Template Reference

Implements a binary heap data structure for efficient priority queue operations. More...

#include <Heap.hpp>

Public Member Functions

 Heap (size_t initCapacity=16)
 ~Heap ()
size_t getSize () const
pop ()
 Removes and returns the root (min or max, per isMinHeap).
void push (const T &value)
 Inserts value and restores the heap property.
top () const
 Returns the root without removing it.

Detailed Description

template<typename T, bool isMinHeap = true>
class Sleak::Heap< T, isMinHeap >

Implements a binary heap data structure for efficient priority queue operations.

The Heap class maintains a collection of elements with a specific ordering property (min-heap or max-heap). It is suitable for scenarios where you need to efficiently retrieve the minimum or maximum element. Use this class when you need to implement priority queues, scheduling algorithms, or heap-based sorting.

Example Use Cases:

  • Implementing a priority queue for task scheduling.
  • Finding the kth largest element in a data stream.
  • Implementing Dijkstra's shortest path algorithm.
  • Heap sort implementation.

Implementation Details:

  • Uses an array-based representation to store the heap elements.
  • Provides methods for inserting elements and extracting the minimum or maximum element.
  • Maintains the heap property after each operation.

Definition at line 28 of file Heap.hpp.

Constructor & Destructor Documentation

◆ Heap()

template<typename T, bool isMinHeap = true>
Sleak::Heap< T, isMinHeap >::Heap ( size_t initCapacity = 16)
inline

Definition at line 95 of file Heap.hpp.

◆ ~Heap()

template<typename T, bool isMinHeap = true>
Sleak::Heap< T, isMinHeap >::~Heap ( )
inline

Definition at line 100 of file Heap.hpp.

Member Function Documentation

◆ getSize()

template<typename T, bool isMinHeap = true>
size_t Sleak::Heap< T, isMinHeap >::getSize ( ) const
inline

Definition at line 135 of file Heap.hpp.

◆ pop()

template<typename T, bool isMinHeap = true>
T Sleak::Heap< T, isMinHeap >::pop ( )
inline

Removes and returns the root (min or max, per isMinHeap).

Definition at line 116 of file Heap.hpp.

◆ push()

template<typename T, bool isMinHeap = true>
void Sleak::Heap< T, isMinHeap >::push ( const T & value)
inline

Inserts value and restores the heap property.

Definition at line 106 of file Heap.hpp.

◆ top()

template<typename T, bool isMinHeap = true>
T Sleak::Heap< T, isMinHeap >::top ( ) const
inline

Returns the root without removing it.

Definition at line 128 of file Heap.hpp.