ORIGINAL
Loading...
Searching...
No Matches
prique.h
Go to the documentation of this file.
1#ifndef PRIQUE_H
2#define PRIQUE_H
3
12#include "algorithms.h"
13#include "blocksList.h"
14#include "comparator.h"
15#include "containerAdapter.h"
16#include "types.h"
17
18namespace original
19{
42 template<typename TYPE,
43 template <typename> typename Callback = increaseComparator,
44 template <typename, typename> typename SERIAL = blocksList,
45 template <typename> typename ALLOC = allocator>
46 requires Compare<Callback<TYPE>, TYPE>
47 class prique final : public containerAdapter<TYPE, SERIAL, ALLOC>
48 {
49 Callback<TYPE> compare_;
50
51 public:
60 const Callback<TYPE>& compare = Callback<TYPE>{});
61
69 prique(const std::initializer_list<TYPE>& lst,
70 const Callback<TYPE>& compare = Callback<TYPE>{});
71
78
86
93 prique(prique&& other) noexcept;
94
103
120 void swap(prique& other) noexcept;
121
128 void push(const TYPE& e);
129
138
144 TYPE top() const;
145
150 [[nodiscard]] std::string className() const override;
151 };
152}
153
154
155 template<typename TYPE,
156 template <typename> typename Callback,
157 template <typename, typename> typename SERIAL,
158 template <typename> typename ALLOC>
161 : containerAdapter<TYPE, SERIAL, ALLOC>(serial), compare_(compare)
162 {
163 algorithms::heapInit(this->serial_.begin(), this->serial_.last(), this->compare_);
164 }
165
166 template<typename TYPE,
167 template <typename> typename Callback,
168 template <typename, typename> typename SERIAL,
169 template <typename> typename ALLOC>
171 original::prique<TYPE, Callback, SERIAL, ALLOC>::prique(const std::initializer_list<TYPE>& lst, const Callback<TYPE>& compare)
172 : prique(SERIAL<TYPE, ALLOC<TYPE>>(lst), compare) {}
173
174 template<typename TYPE,
175 template <typename> typename Callback,
176 template <typename, typename> typename SERIAL,
177 template <typename> typename ALLOC>
181
182 template<typename TYPE,
183 template <typename> typename Callback,
184 template <typename, typename> typename SERIAL,
185 template <typename> typename ALLOC>
188 {
189 if (this == &other) return *this;
190 this->serial_ = other.serial_;
191 compare_ = other.compare_;
192 return *this;
193 }
194
195 template<typename TYPE,
196 template <typename> typename Callback,
197 template <typename, typename> typename SERIAL,
198 template <typename> typename ALLOC>
204
205 template<typename TYPE,
206 template <typename> typename Callback,
207 template <typename, typename> typename SERIAL,
208 template <typename> typename ALLOC>
211 {
212 if (this == &other)
213 return *this;
214
215 this->serial_ = std::move(other.serial_);
216 this->compare_ = std::move(other.compare_);
217 return *this;
218 }
219
220 template<typename TYPE,
221 template <typename> typename Callback,
222 template <typename, typename> typename SERIAL,
223 template <typename> typename ALLOC>
230
231 template<typename TYPE,
232 template <typename> typename Callback,
233 template <typename, typename> typename SERIAL,
234 template <typename> typename ALLOC>
237 {
238 this->serial_.pushEnd(e);
239 algorithms::heapAdjustUp(this->serial_.begin(), this->serial_.last(), this->compare_);
240 }
241
242 template<typename TYPE,
243 template <typename> typename Callback,
244 template <typename, typename> typename SERIAL,
245 template <typename> typename ALLOC>
248 {
249 if (this->empty()) throw noElementError();
250
251 algorithms::swap(this->serial_.begin(), this->serial_.last());
252 TYPE res = this->serial_.popEnd();
253 algorithms::heapAdjustDown(this->serial_.begin(), this->serial_.last(), this->serial_.begin(), this->compare_);
254 return res;
255 }
256
257 template<typename TYPE,
258 template <typename> typename Callback,
259 template <typename, typename> typename SERIAL,
260 template <typename> typename ALLOC>
263 {
264 return this->serial_.getBegin();
265 }
266
267 template<typename TYPE,
268 template <typename> typename Callback,
269 template <typename, typename> typename SERIAL,
270 template <typename> typename ALLOC>
273 {
274 return "prique";
275 }
276
277#endif //PRIQUE_H
Standard algorithm implementations for iterator-based containers.
A block-based list implementation.
static void heapInit(const iterator< TYPE > &begin, const iterator< TYPE > &end, const Callback &compares)
Initializes a heap structure from a range of iterators.
static void swap(const iterator< TYPE > &it1, const iterator< TYPE > &it2) noexcept
Swaps the values of two elements.
static void heapAdjustUp(const iterator< TYPE > &begin, const iterator< TYPE > &current, const Callback &compares)
Adjusts a heap structure upwards from a given iterator.
static void heapAdjustDown(const iterator< TYPE > &begin, const iterator< TYPE > &range, const iterator< TYPE > &current, const Callback &compares)
Adjusts a heap structure downwards starting from a given iterator.
Adapter class that provides unified interface for various container types.
Definition containerAdapter.h:55
SERIAL< TYPE, ALLOC< TYPE > > serial_
The underlying container instance.
Definition containerAdapter.h:62
void swap(containerAdapter &other) noexcept
Swaps the contents of this container adapter with another.
Definition containerAdapter.h:171
Exception for missing element requests.
Definition error.h:298
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Heap-based priority queue container.
Definition prique.h:48
prique(const std::initializer_list< TYPE > &lst, const Callback< TYPE > &compare=Callback< TYPE >{})
Constructs from initializer list with comparator and allocator.
Definition prique.h:171
TYPE top() const
Accesses highest priority element.
Definition prique.h:262
prique(const SERIAL< TYPE, ALLOC< TYPE > > &serial=SERIAL< TYPE, ALLOC< TYPE > >{}, const Callback< TYPE > &compare=Callback< TYPE >{})
Constructs priority queue with container, comparator and allocator.
Definition prique.h:160
void push(const TYPE &e)
Inserts element maintaining heap property.
Definition prique.h:236
prique(prique &&other) noexcept
Move constructs a priority queue with allocator propagation.
Definition prique.h:200
void swap(prique &other) noexcept
Swaps contents with another priority queue.
Definition prique.h:225
prique & operator=(const prique &other)
Copy assignment operator.
Definition prique.h:187
std::string className() const override
Gets class name identifier.
Definition prique.h:272
prique(const prique &other)
Copy constructs a priority queue with allocator propagation.
Definition prique.h:179
TYPE pop()
Extracts highest priority element.
Definition prique.h:247
prique & operator=(prique &&other) noexcept
Move assignment operator.
Definition prique.h:210
Abstract base class for sequential containers with index-based access.
Definition serial.h:34
Comparator base class and concrete comparator classes.
Combines Comparable and CallbackOf for comparison callbacks.
Definition types.h:377
Base class for container adapters with common interfaces.
Main namespace for the project Original.
Definition algorithms.h:21
Standard namespace extensions for original::alternative.
Definition allocator.h:351
void swap(original::objPoolAllocator< TYPE > &lhs, original::objPoolAllocator< TYPE > &rhs) noexcept
Specialization of std::swap for objPoolAllocator.
Definition allocator.h:635
Core type system foundations and concept definitions.