libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
priorityqueue.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstddef>
11#include <queue>
12#include <vector>
13#include <functional>
15
17
30template <typename T, typename Compare = std::less<T>>
32 public:
34 PriorityQueue() = default;
35
38
41
43 ~PriorityQueue() = default;
44
47 d = other.d;
48 return *this;
49 }
50
53 d = std::move(other.d);
54 return *this;
55 }
56
57 // -- Capacity --
58
60 bool isEmpty() const { return d.empty(); }
61
63 size_t size() const { return d.size(); }
64
65 // -- Access --
66
68 const T &top() const { return d.top(); }
69
70 // -- Modifiers --
71
76 void push(const T &value) {
77 d.push(value);
78 return;
79 }
80
85 void push(T &&value) {
86 d.push(std::move(value));
87 return;
88 }
89
94 T pop() {
95 T val = d.top();
96 d.pop();
97 return val;
98 }
99
104 void swap(PriorityQueue &other) noexcept {
105 d.swap(other.d);
106 return;
107 }
108
109 private:
110 std::priority_queue<T, std::vector<T>, Compare> d;
111};
112
Dynamic array container wrapping std::vector.
Definition list.h:40
Priority queue container wrapping std::priority_queue.
Definition priorityqueue.h:31
void push(const T &value)
Pushes a value into the priority queue.
Definition priorityqueue.h:76
PriorityQueue & operator=(PriorityQueue &&other) noexcept
Move assignment operator.
Definition priorityqueue.h:52
~PriorityQueue()=default
Destructor.
bool isEmpty() const
Returns true if the priority queue has no elements.
Definition priorityqueue.h:60
void push(T &&value)
Pushes a value into the priority queue (move overload).
Definition priorityqueue.h:85
PriorityQueue(const PriorityQueue &other)
Copy constructor.
Definition priorityqueue.h:37
const T & top() const
Returns a const reference to the highest-priority element.
Definition priorityqueue.h:68
PriorityQueue(PriorityQueue &&other) noexcept
Move constructor.
Definition priorityqueue.h:40
PriorityQueue()=default
Default constructor. Creates an empty priority queue.
size_t size() const
Returns the number of elements.
Definition priorityqueue.h:63
void swap(PriorityQueue &other) noexcept
Swaps contents with another priority queue.
Definition priorityqueue.h:104
PriorityQueue & operator=(const PriorityQueue &other)
Copy assignment operator.
Definition priorityqueue.h:46
T pop()
Removes and returns the highest-priority element.
Definition priorityqueue.h:94
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56