MCPcopy Create free account
hub / github.com/FastLED/FastLED / PriorityQueue

Class PriorityQueue

src/fl/stl/priority_queue.h:74–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72template <typename T, typename Compare = fl::less<T>,
73 typename VectorT = vector<T>>
74class PriorityQueue {
75 public:
76 using value_type = T;
77 using size_type = fl::size;
78 using compare_type = Compare;
79
80 PriorityQueue() FL_NOEXCEPT = default;
81 explicit PriorityQueue(memory_resource* resource) : _data(resource) {}
82 explicit PriorityQueue(const Compare &comp) : _comp(comp) {}
83 PriorityQueue(const Compare &comp, memory_resource* resource) : _data(resource), _comp(comp) {}
84
85 void push(const T &value) {
86 _data.push_back(value);
87 push_heap(_data.begin(), _data.end(), _comp);
88 }
89
90 void push(T &&value) {
91 _data.push_back(fl::move(value));
92 push_heap(_data.begin(), _data.end(), _comp);
93 }
94
95 template<typename... Args>
96 void emplace(Args&&... args) {
97 _data.emplace_back(fl::forward<Args>(args)...);
98 push_heap(_data.begin(), _data.end(), _comp);
99 }
100
101 void pop() {
102 pop_heap(_data.begin(), _data.end(), _comp);
103 _data.pop_back();
104 }
105
106 const T &top() const { return _data.front(); }
107
108 bool empty() const { return _data.size() == 0; }
109 fl::size size() const { return _data.size(); }
110
111 const Compare &compare() const { return _comp; }
112 memory_resource* get_memory_resource() const { return _data.get_resource(); }
113
114 /// Equality comparison
115 bool operator==(const PriorityQueue& other) const {
116 return _data == other._data;
117 }
118
119 /// Inequality comparison
120 bool operator!=(const PriorityQueue& other) const {
121 return _data != other._data;
122 }
123
124 /// Lexicographic comparison
125 bool operator<(const PriorityQueue& other) const {
126 return _data < other._data;
127 }
128
129 /// Less-than-or-equal comparison
130 bool operator<=(const PriorityQueue& other) const {
131 return _data <= other._data;

Callers

nothing calls this directly

Calls 1

frontMethod · 0.45

Tested by

no test coverage detected