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

A list where elements are stored with associated priorities. More...

#include <PriorityList.hpp>

Public Member Functions

getHighestPriorityElement () const
 Returns the element with the highest priority.
void insert (const T &element, int priority)
 Inserts an element with the given priority.
void removeHighestPriorityElement ()
 Removes the element with the highest priority.

Detailed Description

template<typename T>
class Sleak::PriorityList< T >

A list where elements are stored with associated priorities.

This class provides a way to store elements with priorities and efficiently retrieve or remove the element with the highest priority. It is suitable for scenarios where you need to manage a collection of items with different priorities, such as task scheduling, event handling, or AI decision-making.

Example Use Cases:

  • Task scheduling based on priority levels.
  • Event handling where events have different priorities.
  • AI decision-making where actions have different priorities.

Implementation Details:

  • Uses a List to store pairs of (element, priority).
  • Elements are kept sorted by priority for efficient retrieval.
  • Provides methods for inserting elements with priorities, retrieving the highest priority element, and removing it.

Definition at line 32 of file PriorityList.hpp.

Member Function Documentation

◆ getHighestPriorityElement()

template<typename T>
T Sleak::PriorityList< T >::getHighestPriorityElement ( ) const
inline

Returns the element with the highest priority.

Returns
The element with the highest priority.
Exceptions
std::runtime_errorif the list is empty.

Definition at line 55 of file PriorityList.hpp.

◆ insert()

template<typename T>
void Sleak::PriorityList< T >::insert ( const T & element,
int priority )
inline

Inserts an element with the given priority.

Parameters
elementThe element to insert.
priorityThe priority of the element.

Definition at line 40 of file PriorityList.hpp.

◆ removeHighestPriorityElement()

template<typename T>
void Sleak::PriorityList< T >::removeHighestPriorityElement ( )
inline

Removes the element with the highest priority.

Exceptions
std::runtime_errorif the list is empty.

Definition at line 67 of file PriorityList.hpp.