FastLED 3.9.15
Loading...
Searching...
No Matches
fl::priority_queue_stable< T, Compare > Class Template Reference

Detailed Description

template<typename T, typename Compare = fl::less<T>>
class fl::priority_queue_stable< T, Compare >

Stable priority queue that maintains FIFO ordering for equal-priority elements.

This is a wrapper around fl::PriorityQueue that adds a monotonic sequence counter to ensure stable (FIFO) ordering when elements have equal priority according to the comparison function.

Template Parameters:

  • T: Element type (must be copyable)
  • Compare: Comparison function (default: fl::less<T> for max-heap behavior)

By default, this creates a MAX-HEAP (largest element has highest priority). For custom types with special priority ordering, define operator< and use fl::greater<T>:

struct Task {
int priority;
bool operator<(const Task& o) const { return priority > o.priority; } // Invert for max-heap
};
fl::priority_queue_stable<Task, fl::greater<Task>> queue; // Use greater with inverted operator<
bool operator<(const priority_queue_stable &other) const
Lexicographic comparison.
Stable priority queue that maintains FIFO ordering for equal-priority elements.

Example (default max-heap for integers):

queue.push(3); // Same priority as first 3
// Pop order: 3 (first), 3 (second), 1 - FIFO for equal priorities
void push(const value_type &value)
Add an element to the back of the queue.
Definition queue.h:103
A first-in, first-out (FIFO) queue container adapter.
Definition queue.h:17

Definition at line 180 of file priority_queue.h.

#include <priority_queue.h>

+ Inheritance diagram for fl::priority_queue_stable< T, Compare >:
+ Collaboration diagram for fl::priority_queue_stable< T, Compare >:

Classes

struct  StableElement
 

Public Types

using size_type = fl::size
 
using value_type = T
 

Public Member Functions

 priority_queue_stable () FL_NOEXCEPT
 
void clear ()
 Clear all elements from the queue.
 
template<typename... Args>
void emplace (Args &&... args)
 
bool empty () const
 Check if the queue is empty.
 
bool operator!= (const priority_queue_stable &other) const
 Inequality comparison.
 
bool operator< (const priority_queue_stable &other) const
 Lexicographic comparison.
 
bool operator<= (const priority_queue_stable &other) const
 Less-than-or-equal comparison.
 
bool operator== (const priority_queue_stable &other) const
 Equality comparison.
 
bool operator> (const priority_queue_stable &other) const
 Greater-than comparison.
 
bool operator>= (const priority_queue_stable &other) const
 Greater-than-or-equal comparison.
 
void pop ()
 Remove the top element from the queue.
 
void push (const T &value)
 Push an element into the priority queue.
 
fl::size size () const
 Get the number of elements in the queue.
 
const T & top () const
 Access the top element (highest priority)
 

Private Attributes

u64 mNextSequence
 
fl::PriorityQueue< StableElementmQueue
 

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