aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
sortedPriorityQueue_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41#pragma once
42
43
45
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
47
48namespace gum {
49
50 // basic constructor
51 template < typename Val, typename Priority, typename Cmp >
53 _nodes_(capacity, true, true), _tree_cmp_(compare) {
54 GUM_CONSTRUCTOR(SortedPriorityQueue);
55 }
56
57 // initializer list constructor
58 template < typename Val, typename Priority, typename Cmp >
59 SortedPriorityQueue< Val, Priority, Cmp >::SortedPriorityQueue(
60 std::initializer_list< std::pair< Val, Priority > > list) :
61 _nodes_(Size(list.size()) / 2, true, true) {
62 // fill the queue
63 for (const auto& elt: list) {
64 insert(elt.first, elt.second);
65 }
66
67 GUM_CONSTRUCTOR(SortedPriorityQueue);
68 }
69
70 // copy constructor
71 template < typename Val, typename Priority, typename Cmp >
72 SortedPriorityQueue< Val, Priority, Cmp >::SortedPriorityQueue(
73 const SortedPriorityQueue< Val, Priority, Cmp >& from) :
74 _nodes_(from._nodes_), _tree_cmp_(from._tree_cmp_) {
75 // fill the heap structure
76 for (const auto& node_prio: _nodes_) {
77 _tree_.insert(&node_prio.first);
78 }
79
80 GUM_CONS_CPY(SortedPriorityQueue);
81 }
82
83 // move constructor
84 template < typename Val, typename Priority, typename Cmp >
85 SortedPriorityQueue< Val, Priority, Cmp >::SortedPriorityQueue(
86 SortedPriorityQueue< Val, Priority, Cmp >&& from) noexcept :
87 _tree_(std::move(from._tree_)), _nodes_(std::move(from._nodes_)),
88 _tree_cmp_(std::move(from._tree_cmp_)) {
89 GUM_CONS_MOV(SortedPriorityQueue)
90 }
91
92 // destructor
93 template < typename Val, typename Priority, typename Cmp >
94 SortedPriorityQueue< Val, Priority, Cmp >::~SortedPriorityQueue() {
95 GUM_DESTRUCTOR(SortedPriorityQueue);
96 }
97
98 // copy operator
99 template < typename Val, typename Priority, typename Cmp >
100 SortedPriorityQueue< Val, Priority, Cmp >& SortedPriorityQueue< Val, Priority, Cmp >::operator=(
101 const SortedPriorityQueue< Val, Priority, Cmp >& from) {
102 // avoid self assignment
103 if (this != &from) {
104 GUM_OP_CPY(SortedPriorityQueue)
105
106 try {
107 // set the comparison function
108 _tree_cmp_ = from._tree_cmp_;
109
110 // copy the nodes within the hash table
111 _nodes_ = from._nodes_;
112
113 // fill the AVL tree
114 for (const auto& node_prio: _nodes_)
115 _tree_.insert(&node_prio.first);
116 } catch (...) {
117 _tree_.clear();
118 _nodes_.clear();
119 throw;
120 }
121 }
122
123 return *this;
124 }
125
126 // move operator
127 template < typename Val, typename Priority, typename Cmp >
128 SortedPriorityQueue< Val, Priority, Cmp >& SortedPriorityQueue< Val, Priority, Cmp >::operator=(
129 SortedPriorityQueue< Val, Priority, Cmp >&& from) noexcept {
130 // avoid self assignment
131 if (this != &from) {
132 GUM_OP_MOV(SortedPriorityQueue)
133
134 _nodes_ = std::move(from._nodes_);
135 _tree_ = std::move(from._tree_);
136 _tree_cmp_ = std::move(from._tree_cmp_);
137 }
138
139 return *this;
140 }
141
142 // returns the number of elements in the priority queue
143 template < typename Val, typename Priority, typename Cmp >
144 Size SortedPriorityQueue< Val, Priority, Cmp >::size() const noexcept {
145 return _tree_.size();
146 }
147
148 // indicates whether the priority queue is empty
149 template < typename Val, typename Priority, typename Cmp >
150 bool SortedPriorityQueue< Val, Priority, Cmp >::empty() const noexcept {
151 return (_tree_.empty());
152 }
153
154 // indicates whether the priority queue contains a given value
155 template < typename Val, typename Priority, typename Cmp >
156 bool SortedPriorityQueue< Val, Priority, Cmp >::contains(const Val& val) const noexcept {
157 if constexpr (std::is_scalar_v< Val >) {
158 return _nodes_.exists(AVLTreeNode< Val >(val));
159 } else {
160 AVLTreeNode< Val > xval(std::move(const_cast< Val& >(val)));
161 bool res = _nodes_.exists(xval);
162 const_cast< Val& >(val) = std::move(xval.value);
163 return res;
164 }
165 }
166
167 // returns the element at the top of the priority queue
168 template < typename Val, typename Priority, typename Cmp >
169 const Val& SortedPriorityQueue< Val, Priority, Cmp >::top() const {
170 if (_tree_.empty()) { GUM_ERROR(NotFound, "An empty sorted priority queue has no top element") }
171
172 return _tree_.highestNode()->value;
173 }
174
175 // returns the element at the bottom of the priority queue
176 template < typename Val, typename Priority, typename Cmp >
177 const Val& SortedPriorityQueue< Val, Priority, Cmp >::bottom() const {
178 if (_tree_.empty()) {
179 GUM_ERROR(NotFound, "An empty sorted priority queue has no bottom element")
180 }
181
182 return _tree_.lowestNode()->value;
183 }
184
185 // returns the priority of the top element
186 template < typename Val, typename Priority, typename Cmp >
187 const Priority& SortedPriorityQueue< Val, Priority, Cmp >::topPriority() const {
188 if (_tree_.empty()) { GUM_ERROR(NotFound, "An empty priority queue has no top priority") }
189
190 return _tree_cmp_.getPriority(_tree_.highestNode()->value);
191 }
192
193 // returns the priority of the top element
194 template < typename Val, typename Priority, typename Cmp >
195 const Priority& SortedPriorityQueue< Val, Priority, Cmp >::bottomPriority() const {
196 if (_tree_.empty()) { GUM_ERROR(NotFound, "An empty priority queue has no bottom priority") }
197
198 return _tree_cmp_.getPriority(_tree_.lowestNode()->value);
199 }
200
201 // removes the top element from the priority queue and return it
202 template < typename Val, typename Priority, typename Cmp >
203 Val SortedPriorityQueue< Val, Priority, Cmp >::popTop() {
204 if (_tree_.empty()) { GUM_ERROR(NotFound, "An empty sorted priority queue has no top element") }
205
206 // erase the node from the tree
207 AVLNode* node = _tree_.highestNode();
208 _tree_.erase(node);
209
210 // erase the node from the hash table
211 Val v = std::move(node->value);
212 _nodes_.erase(*node);
213
214 return v;
215 }
216
217 // removes the top element from the priority queue and return it
218 template < typename Val, typename Priority, typename Cmp >
219 Val SortedPriorityQueue< Val, Priority, Cmp >::pop() {
220 return popTop();
221 }
222
223 // removes the bottom element from the priority queue and return it
224 template < typename Val, typename Priority, typename Cmp >
225 Val SortedPriorityQueue< Val, Priority, Cmp >::popBottom() {
226 if (_tree_.empty()) {
227 GUM_ERROR(NotFound, "An empty sorted priority queue has no bottom element")
228 }
229
230 // erase the node from the tree
231 AVLNode* node = _tree_.lowestNode();
232 _tree_.erase(node);
233
234 // erase the node from the hash table
235 Val v = std::move(node->value);
236 _nodes_.erase(*node);
237
238 return v;
239 }
240
241 // inserts a new (a copy) element in the priority queue
242 template < typename Val, typename Priority, typename Cmp >
243 typename SortedPriorityQueue< Val, Priority, Cmp >::const_reference
244 SortedPriorityQueue< Val, Priority, Cmp >::insert(const Val& val, const Priority& priority) {
245 // create the entry in the _nodes_ hashtable (if the element already exists,
246 // _nodes_.insert will raise a DuplicateElement exception)
247 Priority new_priority(priority);
248 const auto& new_elt = _nodes_.insert(AVLNode(val), std::move(new_priority));
249
250 // update the tree
251 _tree_.insert(const_cast< AVLTreeNode< Val >* >(&new_elt.first));
252
253 return new_elt.first.value;
254 }
255
256 // inserts by move a new element in the priority queue
257 template < typename Val, typename Priority, typename Cmp >
258 typename SortedPriorityQueue< Val, Priority, Cmp >::const_reference
259 SortedPriorityQueue< Val, Priority, Cmp >::insert(Val&& val, Priority&& priority) {
260 if constexpr (std::is_move_constructible_v< Val >) {
261 // create the entry in the indices hashtable (if the element already exists,
262 // _nodes_.insert will raise a DuplicateElement exception)
263 const auto& new_elt = _nodes_.insert(AVLNode(std::move(val)), std::move(priority));
264
265 // update the tree
266 _tree_.insert(const_cast< AVLTreeNode< Val >* >(&new_elt.first));
267 return new_elt.first.value;
268 } else {
269 return insert(val, priority);
270 }
271 }
272
273 // emplace a new element into the priority queue
274 template < typename Val, typename Priority, typename Cmp >
275 template < typename... Args >
276 typename SortedPriorityQueue< Val, Priority, Cmp >::const_reference
277 SortedPriorityQueue< Val, Priority, Cmp >::emplace(Args&&... args) {
278 auto new_elt = std::make_pair< Val, Priority >(std::forward< Args >(args)...);
279 return insert(std::move(new_elt.first), std::move(new_elt.second));
280 }
281
282 // removes the top of the priority queue (but does not return it)
283 template < typename Val, typename Priority, typename Cmp >
284 void SortedPriorityQueue< Val, Priority, Cmp >::eraseTop() {
285 if (_tree_.empty()) return;
286 AVLNode* node = _tree_.highestNode();
287 _tree_.erase(node);
288 _nodes_.erase(*node);
289 }
290
291 // removes the bottom of the priority queue (but does not return it)
292 template < typename Val, typename Priority, typename Cmp >
293 void SortedPriorityQueue< Val, Priority, Cmp >::eraseBottom() {
294 if (_tree_.empty()) { return; }
295 AVLNode* node = _tree_.lowestNode();
296 _tree_.erase(node);
297 _nodes_.erase(*node);
298 }
299
300 // returns the node in the hash table corresponding to a given external value
301 template < typename Val, typename Priority, typename Cmp >
302 AVLTreeNode< Val >&
303 SortedPriorityQueue< Val, Priority, Cmp >::getNodeFromExternalValue_(const Val& val) const {
304 // here, we optimize the code for scalars and GraphChanges. For those types,
305 // it is faster to make one copy rather than 2 moves
306 if constexpr (std::is_scalar_v< Val > || std::is_base_of_v< GraphChange, Val >) {
307 return const_cast< AVLTreeNode< Val >& >(_nodes_.key(AVLTreeNode< Val >(val)));
308 } else {
309 AVLTreeNode< Val > xval(std::move(const_cast< Val& >(val)));
310 const bool found = _nodes_.exists(xval);
311 if (found) {
312 auto& node = const_cast< AVLTreeNode< Val >& >(_nodes_.key(xval));
313 const_cast< Val& >(val) = std::move(xval.value);
314 return node;
315 } else {
316 const_cast< Val& >(val) = std::move(xval.value);
317 GUM_ERROR(NotFound, "element not found in sorted priority queue")
318 }
319 }
320 }
321
322 // returns the node in the hash table corresponding to a given external value
323 template < typename Val, typename Priority, typename Cmp >
324 optional_ref< AVLTreeNode< Val > >
325 SortedPriorityQueue< Val, Priority, Cmp >::tryGetNodeFromExternalValue_(
326 const Val& val) const {
327 // here, we optimize the code for scalars and GraphChanges. For those types,
328 // it is faster to make one copy rather than 2 moves
329 if constexpr (std::is_scalar_v< Val > || std::is_base_of_v< GraphChange, Val >) {
330 auto key = _nodes_.tryGetKey(AVLTreeNode< Val >(val));
331 return key.has_value() ? optional_ref{const_cast< AVLTreeNode< Val >& >(key.value())}
332 : optional_ref< AVLTreeNode< Val > >{};
333 } else {
334 AVLTreeNode< Val > xval(std::move(const_cast< Val& >(val)));
335 auto key = _nodes_.tryGetKey(xval);
336 const_cast< Val& >(val) = std::move(xval.value);
337 return key.has_value() ? optional_ref{const_cast< AVLTreeNode< Val >& >(key.value())}
338 : optional_ref< AVLTreeNode< Val > >{};
339 }
340 }
341
342 // returns the node in the hash table corresponding to a given value
343 template < typename Val, typename Priority, typename Cmp >
344 AVLTreeNode< Val >&
345 SortedPriorityQueue< Val, Priority, Cmp >::getNodeFromInternalValue_(const Val& val) const {
346 // Some compilers are optimizing _tree_cmp_.getNode(val) for Val=string. This
347 // induces a lot of warnings. To prevent this, we have an optimized code for
348 // non-strings and a less optimal but warning-free
349 if constexpr (!is_basic_string< Val >::value) {
350 return const_cast< AVLTreeNode< Val >& >(_nodes_.key(*(_tree_cmp_.getNode(val))));
351 } else {
352 return getNodeFromExternalValue_(val);
353 }
354 }
355
356 // returns the "internal" value stored into the queue corresponding to val
357 template < typename Val, typename Priority, typename Cmp >
358 typename SortedPriorityQueue< Val, Priority, Cmp >::const_reference
359 SortedPriorityQueue< Val, Priority, Cmp >::operator[](const Val& val) const {
360 // if this method is called, then val should be an external value
361 return getNodeFromExternalValue_(val).value;
362 }
363
364 // returns the a pointer on the "internal" value stored into the queue or nullptr
365 template < typename Val, typename Priority, typename Cmp >
366 optional_ref< const Val >
367 SortedPriorityQueue< Val, Priority, Cmp >::tryGet(const Val& val) const {
368 // if this method is called, then val should be an external value
369 auto node = tryGetNodeFromExternalValue_(val);
370 return node.has_value() ? optional_ref< const Val >{node->value} : optional_ref< const Val >{};
371 }
372
373 // removes a given element from the priority queue (but does not return it)
374 template < typename Val, typename Priority, typename Cmp >
375 void SortedPriorityQueue< Val, Priority, Cmp >::erase(const Val& val, bool internal_val) {
376 if (contains(val)) {
377 AVLNode& node
378 = internal_val ? getNodeFromInternalValue_(val) : getNodeFromExternalValue_(val);
379 _tree_.erase(&node);
380 _nodes_.erase(node);
381 }
382 }
383
384 // modifies the priority of a given element
385 template < typename Val, typename Priority, typename Cmp >
386 void SortedPriorityQueue< Val, Priority, Cmp >::setPriority(const Val& elt,
387 const Priority& new_priority,
388 bool internal_val) {
389 if (!contains(elt)) {
391 "The sorted priority queue does not contain"
392 << elt << ". Hence it is not possible to change its priority")
393 }
394 AVLNode& node = internal_val ? getNodeFromInternalValue_(elt) : getNodeFromExternalValue_(elt);
395 _tree_.erase(&node);
396 _nodes_[node] = new_priority;
397 _tree_.insert(&node);
398 }
399
400 // modifies the priority of a given element
401 template < typename Val, typename Priority, typename Cmp >
402 void SortedPriorityQueue< Val, Priority, Cmp >::setPriority(const Val& elt,
403 Priority&& new_priority,
404 bool internal_val) {
405 if (!contains(elt)) {
407 "The sorted priority queue does not contain"
408 << elt << ". Hence it is not possible to change its priority")
409 }
410 AVLNode& node = internal_val ? getNodeFromInternalValue_(elt) : getNodeFromExternalValue_(elt);
411 _tree_.erase(&node);
412 _nodes_[node] = std::move(new_priority);
413 _tree_.insert(&node);
414 }
415
416 // returns the priority of a given element
417 template < typename Val, typename Priority, typename Cmp >
418 const Priority& SortedPriorityQueue< Val, Priority, Cmp >::priority(const Val& elt,
419 bool internal_val) const {
420 return _nodes_[internal_val ? getNodeFromInternalValue_(elt) : getNodeFromExternalValue_(elt)];
421 }
422
423 // removes all the elements from the queue
424 template < typename Val, typename Priority, typename Cmp >
425 void SortedPriorityQueue< Val, Priority, Cmp >::clear() {
426 _tree_.clear();
427 _nodes_.clear();
428 }
429
430 // displays the content of the queue
431 template < typename Val, typename Priority, typename Cmp >
432 std::string SortedPriorityQueue< Val, Priority, Cmp >::toString() const {
433 bool deja = false;
434 std::stringstream stream;
435 stream << "[";
436
437 // parse the tree from the highest element to the lowest
438 for (auto iter = _tree_.rbegin(); iter != _tree_.rend(); ++iter) {
439 if (deja) stream << " ; ";
440 else deja = true;
441
442 stream << "(" << iter->value << ", " << _tree_cmp_.getPriority(iter->value) << ")";
443 }
444
445 stream << "]";
446
447 return stream.str();
448 }
449
451 template < typename Val, typename Priority, typename Cmp >
452 typename SortedPriorityQueue< Val, Priority, Cmp >::iterator
453 SortedPriorityQueue< Val, Priority, Cmp >::begin() const {
454 return iterator(*this);
455 }
456
458 template < typename Val, typename Priority, typename Cmp >
459 constexpr const typename SortedPriorityQueue< Val, Priority, Cmp >::iterator&
460 SortedPriorityQueue< Val, Priority, Cmp >::end() const {
461 return *(reinterpret_cast< const iterator* >(_SortedPriorityQueue_end_));
462 }
463
465 template < typename Val, typename Priority, typename Cmp >
466 typename SortedPriorityQueue< Val, Priority, Cmp >::reverse_iterator
467 SortedPriorityQueue< Val, Priority, Cmp >::rbegin() const {
468 return reverse_iterator(*this, true);
469 }
470
472 template < typename Val, typename Priority, typename Cmp >
473 constexpr const typename SortedPriorityQueue< Val, Priority, Cmp >::reverse_iterator&
474 SortedPriorityQueue< Val, Priority, Cmp >::rend() const {
475 return *(reinterpret_cast< const reverse_iterator* >(_SortedPriorityQueue_rend_));
476 }
477
479 template < typename Val, typename Priority, typename Cmp >
480 typename SortedPriorityQueue< Val, Priority, Cmp >::iterator_safe
481 SortedPriorityQueue< Val, Priority, Cmp >::beginSafe() {
482 return iterator_safe(*this);
483 }
484
486 template < typename Val, typename Priority, typename Cmp >
487 constexpr const typename SortedPriorityQueue< Val, Priority, Cmp >::iterator_safe&
488 SortedPriorityQueue< Val, Priority, Cmp >::endSafe() const {
489 return *(reinterpret_cast< const iterator_safe* >(_SortedPriorityQueue_end_safe_));
490 }
491
493 template < typename Val, typename Priority, typename Cmp >
494 typename SortedPriorityQueue< Val, Priority, Cmp >::reverse_iterator_safe
495 SortedPriorityQueue< Val, Priority, Cmp >::rbeginSafe() {
496 return reverse_iterator_safe(*this, true);
497 }
498
500 template < typename Val, typename Priority, typename Cmp >
501 constexpr const typename SortedPriorityQueue< Val, Priority, Cmp >::reverse_iterator_safe&
502 SortedPriorityQueue< Val, Priority, Cmp >::rendSafe() const {
503 return *(reinterpret_cast< const reverse_iterator_safe* >(_SortedPriorityQueue_rend_safe_));
504 }
505
506 // return the size of the array storing the priority queue
507 template < typename Val, typename Priority, typename Cmp >
508 Size SortedPriorityQueue< Val, Priority, Cmp >::capacity() const noexcept {
509 return Size(_nodes_.capacity());
510 }
511
512 // changes the size of the array storing the priority queue
513 template < typename Val, typename Priority, typename Cmp >
514 void SortedPriorityQueue< Val, Priority, Cmp >::resize(Size new_size) {
515 if (new_size < _tree_.size() / 2) return;
516 _nodes_.resize(new_size);
517 }
518
520
522 template < typename Val, typename Priority, typename Cmp >
523 SortedPriorityQueueIterator< Val, Priority, Cmp >::SortedPriorityQueueIterator(
524 const SortedPriorityQueue< Val, Priority, Cmp >& queue,
525 const bool begin) noexcept :
526 SharedAVLTreeReverseIterator< Val, TreeCmp >(queue._tree_, begin) {
527 GUM_CONSTRUCTOR(SortedPriorityQueueIterator)
528 }
529
531 template < typename Val, typename Priority, typename Cmp >
532 SortedPriorityQueueIterator< Val, Priority, Cmp >::SortedPriorityQueueIterator(
533 const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) noexcept :
534 SharedAVLTreeReverseIterator< Val, TreeCmp >(from) {
535 GUM_CONS_CPY(SortedPriorityQueueIterator)
536 }
537
539 template < typename Val, typename Priority, typename Cmp >
540 SortedPriorityQueueIterator< Val, Priority, Cmp >::SortedPriorityQueueIterator(
541 SortedPriorityQueueIterator< Val, Priority, Cmp >&& from) noexcept :
542 SharedAVLTreeReverseIterator< Val, TreeCmp >(std::move(from)) {
543 GUM_CONS_MOV(SortedPriorityQueueIterator)
544 }
545
547 template < typename Val, typename Priority, typename Cmp >
548 SortedPriorityQueueIterator< Val, Priority, Cmp >::~SortedPriorityQueueIterator() noexcept {
549 GUM_DESTRUCTOR(SortedPriorityQueueIterator)
550 }
551
553 template < typename Val, typename Priority, typename Cmp >
554 SortedPriorityQueueIterator< Val, Priority, Cmp >&
555 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator=(
556 const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) noexcept {
557 SharedAVLTreeReverseIterator< Val, TreeCmp >::operator=(from);
558 return *this;
559 }
560
562 template < typename Val, typename Priority, typename Cmp >
563 SortedPriorityQueueIterator< Val, Priority, Cmp >&
564 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator=(
565 SortedPriorityQueueIterator< Val, Priority, Cmp >&& from) noexcept {
566 SharedAVLTreeReverseIterator< Val, TreeCmp >::operator=(std::move(from));
567 return *this;
568 }
569
571 template < typename Val, typename Priority, typename Cmp >
572 bool SortedPriorityQueueIterator< Val, Priority, Cmp >::operator==(
573 const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) const {
574 return SharedAVLTreeReverseIterator< Val, TreeCmp >::operator==(from);
575 }
576
578 template < typename Val, typename Priority, typename Cmp >
579 bool SortedPriorityQueueIterator< Val, Priority, Cmp >::operator!=(
580 const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) const {
581 return !operator==(from);
582 }
583
585 template < typename Val, typename Priority, typename Cmp >
586 SortedPriorityQueueIterator< Val, Priority, Cmp >&
587 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator++() noexcept {
588 SharedAVLTreeReverseIterator< Val, TreeCmp >::operator++();
589 return *this;
590 }
591
593 template < typename Val, typename Priority, typename Cmp >
594 SortedPriorityQueueIterator< Val, Priority, Cmp >&
595 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator+=(const Size k) noexcept {
596 SharedAVLTreeReverseIterator< Val, TreeCmp >::operator+=(k);
597 return *this;
598 }
599
601 template < typename Val, typename Priority, typename Cmp >
602 SortedPriorityQueueIterator< Val, Priority, Cmp >&
603 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator--() noexcept {
604 SharedAVLTreeReverseIterator< Val, TreeCmp >::operator--();
605 return *this;
606 }
607
609 template < typename Val, typename Priority, typename Cmp >
610 SortedPriorityQueueIterator< Val, Priority, Cmp >&
611 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator-=(const Size k) noexcept {
612 SharedAVLTreeReverseIterator< Val, TreeCmp >::operator-=(k);
613 return *this;
614 }
615
617 template < typename Val, typename Priority, typename Cmp >
618 typename SortedPriorityQueueIterator< Val, Priority, Cmp >::const_reference
619 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator*() const {
620 return SharedAVLTreeReverseIterator< Val, TreeCmp >::operator*().value;
621 }
622
624 template < typename Val, typename Priority, typename Cmp >
625 typename SortedPriorityQueueIterator< Val, Priority, Cmp >::const_pointer
626 SortedPriorityQueueIterator< Val, Priority, Cmp >::operator->() const {
627 auto node = SharedAVLTreeReverseIterator< Val, TreeCmp >::operator->();
628 if (node != nullptr) return &(node->value);
629 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
630 }
631
633
634 template < typename Val, typename Priority, typename Cmp >
635 typename SortedPriorityQueueIterator< Val, Priority, Cmp >::const_reference
636 SortedPriorityQueueIterator< Val, Priority, Cmp >::value() const {
637 return operator*();
638 }
639
641
642 template < typename Val, typename Priority, typename Cmp >
643 const Priority& SortedPriorityQueueIterator< Val, Priority, Cmp >::priority() const {
644 auto node = SharedAVLTreeReverseIterator< Val, TreeCmp >::operator->();
645 if (node != nullptr) return TreeIterator::tree().compare().getPriority(node->value);
646 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
647 }
648
650
652 template < typename Val, typename Priority, typename Cmp >
653 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::SortedPriorityQueueIteratorSafe(
654 SortedPriorityQueue< Val, Priority, Cmp >& queue,
655 const bool rbegin) : SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >(queue._tree_, rbegin) {
656 GUM_CONSTRUCTOR(SortedPriorityQueueIteratorSafe)
657 }
658
660 template < typename Val, typename Priority, typename Cmp >
661 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::SortedPriorityQueueIteratorSafe(
662 const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from) :
663 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >(from) {
664 GUM_CONS_CPY(SortedPriorityQueueIteratorSafe)
665 }
666
668 template < typename Val, typename Priority, typename Cmp >
669 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::SortedPriorityQueueIteratorSafe(
670 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&& from) :
671 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >(std::move(from)) {
672 GUM_CONS_CPY(SortedPriorityQueueIteratorSafe)
673 }
674
676 template < typename Val, typename Priority, typename Cmp >
677 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::
678 ~SortedPriorityQueueIteratorSafe() noexcept {
679 GUM_DESTRUCTOR(SortedPriorityQueueIteratorSafe)
680 }
681
683 template < typename Val, typename Priority, typename Cmp >
684 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
685 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator=(
686 const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from) {
687 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator=(from);
688 return *this;
689 }
690
692 template < typename Val, typename Priority, typename Cmp >
693 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
694 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator=(
695 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&& from) {
696 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator=(std::move(from));
697 return *this;
698 }
699
701 template < typename Val, typename Priority, typename Cmp >
702 bool SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator==(
703 const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from) const {
704 return SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator==(from);
705 }
706
708 template < typename Val, typename Priority, typename Cmp >
709 bool SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator!=(
710 const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from) const {
711 return !operator==(from);
712 }
713
715 template < typename Val, typename Priority, typename Cmp >
716 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
717 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator++() noexcept {
718 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator++();
719 return *this;
720 }
721
723 template < typename Val, typename Priority, typename Cmp >
724 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
725 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator+=(const Size k) noexcept {
726 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator+=(k);
727 return *this;
728 }
729
731 template < typename Val, typename Priority, typename Cmp >
732 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
733 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator--() noexcept {
734 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator--();
735 return *this;
736 }
737
739 template < typename Val, typename Priority, typename Cmp >
740 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
741 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator-=(const Size k) noexcept {
742 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator-=(k);
743 return *this;
744 }
745
747 template < typename Val, typename Priority, typename Cmp >
748 typename SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::const_reference
749 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator*() const {
750 return SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator*().value;
751 }
752
754 template < typename Val, typename Priority, typename Cmp >
755 typename SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::const_pointer
756 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::operator->() const {
757 auto node = SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator->();
758 if (node != nullptr) return &(node->value);
759 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
760 }
761
763
764 template < typename Val, typename Priority, typename Cmp >
765 typename SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::const_reference
766 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::value() const {
767 return operator*();
768 }
769
771
772 template < typename Val, typename Priority, typename Cmp >
773 const Priority& SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >::priority() const {
774 auto node = SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >::operator->();
775 if (node != nullptr) return TreeIterator::tree().compare().getPriority(node->value);
776 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
777 }
778
780
782 template < typename Val, typename Priority, typename Cmp >
783 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::SortedPriorityQueueReverseIterator(
784 const SortedPriorityQueue< Val, Priority, Cmp >& queue,
785 const bool rbegin) noexcept : SharedAVLTreeIterator< Val, TreeCmp >(queue._tree_, rbegin) {
786 GUM_CONSTRUCTOR(SortedPriorityQueueReverseIterator)
787 }
788
790 template < typename Val, typename Priority, typename Cmp >
791 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::SortedPriorityQueueReverseIterator(
792 const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) noexcept :
793 SharedAVLTreeIterator< Val, TreeCmp >(from) {
794 GUM_CONS_CPY(SortedPriorityQueueReverseIterator)
795 }
796
798 template < typename Val, typename Priority, typename Cmp >
799 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::SortedPriorityQueueReverseIterator(
800 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&& from) noexcept :
801 SharedAVLTreeIterator< Val, TreeCmp >(std::move(from)) {
802 GUM_CONS_MOV(SortedPriorityQueueReverseIterator)
803 }
804
806 template < typename Val, typename Priority, typename Cmp >
807 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::
808 ~SortedPriorityQueueReverseIterator() noexcept {
809 GUM_DESTRUCTOR(SortedPriorityQueueReverseIterator)
810 }
811
813 template < typename Val, typename Priority, typename Cmp >
814 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
815 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator=(
816 const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) noexcept {
817 SharedAVLTreeIterator< Val, TreeCmp >::operator=(from);
818 return *this;
819 }
820
822 template < typename Val, typename Priority, typename Cmp >
823 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
824 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator=(
825 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&& from) noexcept {
826 SharedAVLTreeIterator< Val, TreeCmp >::operator=(std::move(from));
827 return *this;
828 }
829
831 template < typename Val, typename Priority, typename Cmp >
832 bool SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator==(
833 const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) const {
834 return SharedAVLTreeIterator< Val, TreeCmp >::operator==(from);
835 }
836
838 template < typename Val, typename Priority, typename Cmp >
839 bool SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator!=(
840 const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) const {
841 return !operator==(from);
842 }
843
845 template < typename Val, typename Priority, typename Cmp >
846 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
847 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator++() noexcept {
848 SharedAVLTreeIterator< Val, TreeCmp >::operator++();
849 return *this;
850 }
851
853 template < typename Val, typename Priority, typename Cmp >
854 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
855 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator+=(const Size k) noexcept {
856 SharedAVLTreeIterator< Val, TreeCmp >::operator+=(k);
857 return *this;
858 }
859
861 template < typename Val, typename Priority, typename Cmp >
862 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
863 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator--() noexcept {
864 SharedAVLTreeIterator< Val, TreeCmp >::operator--();
865 return *this;
866 }
867
869 template < typename Val, typename Priority, typename Cmp >
870 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
871 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator-=(const Size k) noexcept {
872 SharedAVLTreeIterator< Val, TreeCmp >::operator-=(k);
873 return *this;
874 }
875
877 template < typename Val, typename Priority, typename Cmp >
878 typename SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::const_reference
879 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator*() const {
880 return SharedAVLTreeIterator< Val, TreeCmp >::operator*().value;
881 }
882
884 template < typename Val, typename Priority, typename Cmp >
885 typename SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::const_pointer
886 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::operator->() const {
887 auto node = SharedAVLTreeIterator< Val, TreeCmp >::operator->();
888 if (node != nullptr) return &(node->value);
889 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
890 }
891
893
894 template < typename Val, typename Priority, typename Cmp >
895 typename SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::const_reference
896 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::value() const {
897 return operator*();
898 }
899
901
902 template < typename Val, typename Priority, typename Cmp >
903 const Priority& SortedPriorityQueueReverseIterator< Val, Priority, Cmp >::priority() const {
904 auto node = SharedAVLTreeIterator< Val, TreeCmp >::operator->();
905 if (node != nullptr) return TreeIterator::tree().compare().getPriority(node->value);
906 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
907 }
908
910
912 template < typename Val, typename Priority, typename Cmp >
913 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::
914 SortedPriorityQueueReverseIteratorSafe(SortedPriorityQueue< Val, Priority, Cmp >& queue,
915 const bool rbegin) :
916 SharedAVLTreeIteratorSafe< Val, TreeCmp >(queue._tree_, rbegin) {
917 GUM_CONSTRUCTOR(SortedPriorityQueueReverseIteratorSafe)
918 }
919
921 template < typename Val, typename Priority, typename Cmp >
922 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::
923 SortedPriorityQueueReverseIteratorSafe(
924 const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from) :
925 SharedAVLTreeIteratorSafe< Val, TreeCmp >(from) {
926 GUM_CONS_CPY(SortedPriorityQueueReverseIteratorSafe)
927 }
928
930 template < typename Val, typename Priority, typename Cmp >
931 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::
932 SortedPriorityQueueReverseIteratorSafe(
933 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&& from) :
934 SharedAVLTreeIteratorSafe< Val, TreeCmp >(std::move(from)) {
935 GUM_CONS_MOV(SortedPriorityQueueReverseIteratorSafe)
936 }
937
939 template < typename Val, typename Priority, typename Cmp >
940 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::
941 ~SortedPriorityQueueReverseIteratorSafe() noexcept {
942 GUM_DESTRUCTOR(SortedPriorityQueueReverseIteratorSafe)
943 }
944
946 template < typename Val, typename Priority, typename Cmp >
947 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&
948 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator=(
949 const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from) {
950 SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator=(from);
951 return *this;
952 }
953
955 template < typename Val, typename Priority, typename Cmp >
956 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&
957 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator=(
958 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&& from) {
959 SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator=(std::move(from));
960 return *this;
961 }
962
964 template < typename Val, typename Priority, typename Cmp >
965 bool SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator==(
966 const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from) const {
967 return SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator==(from);
968 }
969
971 template < typename Val, typename Priority, typename Cmp >
972 bool SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator!=(
973 const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from) const {
974 return !operator==(from);
975 }
976
978 template < typename Val, typename Priority, typename Cmp >
979 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&
980 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator++() noexcept {
981 SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator++();
982 return *this;
983 }
984
986 template < typename Val, typename Priority, typename Cmp >
987 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&
988 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator+=(
989 const Size k) noexcept {
990 SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator+=(k);
991 return *this;
992 }
993
995 template < typename Val, typename Priority, typename Cmp >
996 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&
997 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator--() noexcept {
998 SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator--();
999 return *this;
1000 }
1001
1003 template < typename Val, typename Priority, typename Cmp >
1004 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&
1005 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator-=(
1006 const Size k) noexcept {
1007 SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator-=(k);
1008 return *this;
1009 }
1010
1012 template < typename Val, typename Priority, typename Cmp >
1013 typename SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::const_reference
1014 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator*() const {
1015 return SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator*().value;
1016 }
1017
1019 template < typename Val, typename Priority, typename Cmp >
1020 typename SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::const_pointer
1021 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::operator->() const {
1022 auto node = SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator->();
1023 if (node != nullptr) return &(node->value);
1024 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
1025 }
1026
1028
1029 template < typename Val, typename Priority, typename Cmp >
1030 typename SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::const_reference
1031 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::value() const {
1032 return operator*();
1033 }
1034
1036
1037 template < typename Val, typename Priority, typename Cmp >
1038 const Priority& SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >::priority() const {
1039 auto node = SharedAVLTreeIteratorSafe< Val, TreeCmp >::operator->();
1040 if (node != nullptr) return TreeIterator::tree().compare().getPriority(node->value);
1041 else { GUM_ERROR(NotFound, "The sorted priority queue iterator does not point on any value") }
1042 }
1043
1044 // ===========================================================================
1045 // === IMPLEMENTATION OF SortedPriorityQueue::TreeCmp ===
1046 // ===========================================================================
1047
1048 template < typename Val, typename Priority, typename Cmp >
1049 SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp::TreeCmp(const Cmp& cmp) : _cmp_(cmp) {}
1050
1051 template < typename Val, typename Priority, typename Cmp >
1052 SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp::TreeCmp(Cmp&& cmp) : _cmp_(std::move(cmp)) {}
1053
1054 template < typename Val, typename Priority, typename Cmp >
1055 const Priority&
1056 SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp::getPriority(const Val& v) const {
1057 return *((Priority*)((char*)&v + offset_from_value_to_priority));
1058 }
1059
1060 template < typename Val, typename Priority, typename Cmp >
1061 AVLTreeNode< Val >*
1062 SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp::getNode(const Val& v) const {
1063 return (AVLTreeNode< Val >*)((char*)&v - offset_to_value);
1064 }
1065
1066 template < typename Val, typename Priority, typename Cmp >
1067 bool SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp::operator()(const Val& x,
1068 const Val& y) const {
1069 return _cmp_(getPriority(x), getPriority(y));
1070 }
1071
1072} // namespace gum
1073
1074#endif // DOXYGEN_SHOULD_SKIP_THIS
1075
1076namespace gum {
1077
1079 template < typename Val, typename Priority, typename Cmp >
1080 std::ostream& operator<<(std::ostream& stream,
1082 return stream << queue.toString();
1083 }
1084
1085} // namespace gum
Exception : the element we looked for cannot be found.
A priority queue in which we can iterate over the elements from the top to bottom or conversely.
SortedPriorityQueue(Cmp compare=Cmp(), Size capacity=GUM_PRIORITY_QUEUE_DEFAULT_CAPACITY)
Basic constructor.
std::string toString() const
Displays the content of the queue.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
bool contains(std::string_view s, std::string_view needle)
true if needle in s
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
value_type & operator*()
Returns the value pointed to by the iterator.
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
STL namespace.
Priority queues which can be parsed using iterators.
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:243