aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
sortedPriorityQueue.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 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-2025 *
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
49
50#ifndef GUM_SORTED_PRIORITY_QUEUE_H
51#define GUM_SORTED_PRIORITY_QUEUE_H
52
53#include <cstddef>
54#include <functional>
55#include <sstream>
56#include <string>
57#include <utility>
58#include <vector>
59
60#include <agrum/agrum.h>
61
64
65#include <initializer_list>
66#include <type_traits>
67
68namespace gum {
69
70 template < typename Val, typename Priority, typename Cmp >
72 template < typename Val, typename Priority, typename Cmp >
74
75 template < typename Val, typename Priority, typename Cmp >
77 template < typename Val, typename Priority, typename Cmp >
79
138 template < typename Val, typename Priority = int, typename Cmp = std::less< Priority > >
140 public:
143 using value_type = Val;
144 using reference = Val&;
145 using const_reference = const Val&;
146 using pointer = Val*;
147 using const_pointer = const Val*;
148 using difference_type = std::ptrdiff_t;
154
155
156 // ============================================================================
158 // ============================================================================
160
170 explicit SortedPriorityQueue(Cmp compare = Cmp(),
172
180 explicit SortedPriorityQueue(std::initializer_list< std::pair< Val, Priority > > list);
181
187
193
198
200
201 public:
202 // ============================================================================
204 // ============================================================================
206
220
229
231
232 // ============================================================================
234 // ============================================================================
236
241 Size size() const noexcept;
242
247 bool empty() const noexcept;
248
254 bool contains(const Val& val) const noexcept;
255
257
258 const Val& top() const;
259
261
262 const Val& bottom() const;
263
269 const Priority& topPriority() const;
270
276 const Priority& bottomPriority() const;
277
284
291
298
307 const_reference insert(const Val& val, const Priority& priority);
308
317 const_reference insert(Val&& val, Priority&& priority);
318
327 template < typename... Args >
328 const_reference emplace(Args&&... args);
329
336 void eraseTop();
337
345
355 void erase(const Val& val);
356
363 void setPriority(const Val& elt, const Priority& new_priority);
364
371 void setPriority(const Val& elt, Priority&& new_priority);
372
382 const Priority& priority(const Val& elt) const;
383
387 void clear();
388
393 std::string toString() const;
394
396
397 // ============================================================================
399 // ============================================================================
401
404
406 constexpr const iterator& end() const;
407
410
412 constexpr const reverse_iterator& rend() const;
413
416
418 constexpr const iterator_safe& endSafe() const;
419
422
424 constexpr const reverse_iterator_safe& rendSafe() const;
425
427
428 // ============================================================================
430 // ============================================================================
432
439 Size capacity() const noexcept;
440
446 void resize(Size new_size);
447
449
450#ifndef DOXYGEN_SHOULD_SKIP_THIS
452 using AVLNode = AVLTreeNode< Val >;
453
455 using HashElt = typename std::pair< const AVLTreeNode< Val >, Priority >;
456
458 struct TreeCmp {
459 TreeCmp() = default;
460
461 TreeCmp(const Cmp& cmp) : _cmp_(cmp) {}
462
463 TreeCmp(Cmp&& cmp) : _cmp_(std::move(cmp)) {}
464
465 // get the priority associated with a given AVLTreeNode value. It turns out
466 // that the elements stored into the HashTable are of type HashElt defined
467 // above. Now, the constexpr offset defined below contains precisely the
468 // offset in bytes between Value v and its priority. Function getPriority
469 // therefore just computes the location of the priority and returns it.
470 inline const Priority& getPriority(const Val& v) const {
471 return *((Priority*)((char*)&v + offset_from_value_to_priority));
472 }
473
474 // from a Val instance stored into memory, get the address of the start of
475 // the AVLNode structure that would have contained it. This is useful for
476 // comparing elements in the hashTable without having to create dummy AVLNodes
477 inline AVLTreeNode< Val >* getNode(const Val& v) const {
478 return (AVLTreeNode< Val >*)((char*)&v - offset_to_value);
479 }
480
481 // the comparison function betwwen two contents of two nodes of the AVL tree:
482 // the nodes should be sorted according to their priority
483 constexpr bool operator()(const Val& x, const Val& y) const {
484 return _cmp_(getPriority(x), getPriority(y));
485 }
486
487 Cmp _cmp_;
488
489 // compute the offset in bytes between the location of Val and Priority in
490 // the elements stored into the hash table
491 static constexpr std::size_t offset_to_priority = offsetof(HashElt, second);
492 static constexpr std::size_t offset_to_value = offsetof(AVLTreeNode< Val >, value);
493 static constexpr std::size_t offset_from_value_to_priority
494 = offset_to_priority - offset_to_value;
495 };
496#endif // DOXYGEN_SHOULD_SKIP_THIS
497
498 private:
510 SharedAVLTree< Val, TreeCmp > _tree_;
511
514
516 TreeCmp _tree_cmp_;
517
521 AVLNode& getNode_(const Val& val) const;
522
523#ifndef DOXYGEN_SHOULD_SKIP_THIS
524 // the TreeCmp getnode function induces some warning on some compilers when Val
525 // is a string because some optimizations are made by the compiler in this case.
526 // to avoid this, the getNode_ function above executes different codes depending
527 // on whether Val is different from a string or not. The structs below allow
528 // to make this discrimination at compile time.
529 template < typename T >
530 struct is_basic_string: std::false_type {};
531
532 template < typename T1, typename T2, typename T3 >
533 struct is_basic_string< std::basic_string< T1, T2, T3 > >: std::true_type {};
534#endif // DOXYGEN_SHOULD_SKIP_THIS
535
537 friend iterator;
541 };
542
553 template < typename Val, typename Priority = int, typename Cmp = std::less< Priority > >
555 protected SharedAVLTreeReverseIterator<
556 Val,
557 typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp > {
558 public:
561 using iterator_category = std::bidirectional_iterator_tag;
562 using value_type = Val;
566 using const_pointer = const value_type*;
569
570
571 // ============================================================================
573 // ============================================================================
575
583 const bool begin = true) noexcept;
584
585#ifndef DOXYGEN_SHOULD_SKIP_THIS
586 // constructor for the static end iterator
587 // only sortedPriorityQueue.cpp should use this constructor
588 explicit consteval SortedPriorityQueueIterator(StaticInitializer init) noexcept :
589 SharedAVLTreeReverseIterator< Val, TreeCmp >(init) {}
590#endif // DOXYGEN_SHOULD_SKIP_THIS
591
595
598
601
603
604
605 // ============================================================================
607 // ============================================================================
609
611 SortedPriorityQueueIterator< Val, Priority, Cmp >&
612 operator=(const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) noexcept;
613
615 SortedPriorityQueueIterator< Val, Priority, Cmp >&
616 operator=(SortedPriorityQueueIterator< Val, Priority, Cmp >&& from) noexcept;
617
619 bool operator==(const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) const;
620
622 bool operator!=(const SortedPriorityQueueIterator< Val, Priority, Cmp >& from) const;
623
625
627 SortedPriorityQueueIterator< Val, Priority, Cmp >& operator++() noexcept;
628
630
632 SortedPriorityQueueIterator< Val, Priority, Cmp >& operator+=(const Size k) noexcept;
633
635
637 SortedPriorityQueueIterator< Val, Priority, Cmp >& operator--() noexcept;
638
640
642 SortedPriorityQueueIterator< Val, Priority, Cmp >& operator-=(const Size k) noexcept;
643
650 const_reference operator*() const;
651
653 const_pointer operator->() const;
654
656
658 friend SortedPriorityQueue< Val, Priority, Cmp >;
659 };
660
671 template < typename Val, typename Priority = int, typename Cmp = std::less< Val > >
673 protected SharedAVLTreeReverseIteratorSafe<
674 Val,
675 typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp > {
676 public:
679 using iterator_category = std::bidirectional_iterator_tag;
680 using value_type = Val;
684 using const_pointer = const value_type*;
687
688
689 // ============================================================================
691 // ============================================================================
693
701 const bool rbegin = true);
702
703#ifndef DOXYGEN_SHOULD_SKIP_THIS
704 // constructor for the static endSafe iterator
705 // only sortedPriorityQueue.cpp should use this constructor
706 explicit consteval SortedPriorityQueueIteratorSafe(StaticInitializer init) noexcept :
707 SharedAVLTreeReverseIteratorSafe< Val, TreeCmp >(init) {}
708#endif // DOXYGEN_SHOULD_SKIP_THIS
709
713
716
719
721
722 // ============================================================================
724 // ============================================================================
726
728 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
729 operator=(const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from);
730
732 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&
733 operator=(SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >&& from);
734
736 bool operator==(const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from) const;
737
739 bool operator!=(const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& from) const;
740
742
744 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& operator++() noexcept;
745
747
749 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& operator+=(const Size k) noexcept;
750
752
754 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& operator--() noexcept;
755
757
759 SortedPriorityQueueIteratorSafe< Val, Priority, Cmp >& operator-=(const Size k) noexcept;
760
767 const_reference operator*() const;
768
770 const_pointer operator->() const;
771
773
774 protected:
777 };
778
789 template < typename Val, typename Priority = int, typename Cmp = std::less< Val > >
791 protected SharedAVLTreeIterator<
792 Val,
793 typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp > {
794 public:
797 using iterator_category = std::bidirectional_iterator_tag;
798 using value_type = Val;
802 using const_pointer = const value_type*;
805
806
807 // ============================================================================
809 // ============================================================================
811
820 const bool rbegin = true) noexcept;
821
822#ifndef DOXYGEN_SHOULD_SKIP_THIS
823 // constructor for the static rend iterator
824 // only sortedPriorityQueue.cpp should use this constructor
825 explicit consteval SortedPriorityQueueReverseIterator(StaticInitializer init) noexcept :
826 SharedAVLTreeIterator< Val, TreeCmp >(init) {}
827#endif // DOXYGEN_SHOULD_SKIP_THIS
828
832
836
839
841
842 // ============================================================================
844 // ============================================================================
846
848 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
849 operator=(const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) noexcept;
850
852 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&
853 operator=(SortedPriorityQueueReverseIterator< Val, Priority, Cmp >&& from) noexcept;
854
856 bool operator==(const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) const;
857
859 bool operator!=(const SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& from) const;
860
862
864 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& operator++() noexcept;
865
867
869 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& operator+=(const Size k) noexcept;
870
872
874 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& operator--() noexcept;
875
877
879 SortedPriorityQueueReverseIterator< Val, Priority, Cmp >& operator-=(const Size k) noexcept;
880
887 const_reference operator*() const;
888
890 const_pointer operator->() const;
891
893
894
895 protected:
897 friend SortedPriorityQueue< Val, Priority, Cmp >;
898 };
899
910 template < typename Val, typename Priority = int, typename Cmp = std::less< Val > >
912 protected SharedAVLTreeIteratorSafe<
913 Val,
914 typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp > {
915 public:
918 using iterator_category = std::bidirectional_iterator_tag;
919 using value_type = Val;
923 using const_pointer = const value_type*;
926
927
928 // ============================================================================
930 // ============================================================================
932
941 const bool rbegin = true);
942
943#ifndef DOXYGEN_SHOULD_SKIP_THIS
944 // constructor for the static rendSafe iterator
945 // only sortedPriorityQueue.cpp should use this constructor
946 explicit consteval SortedPriorityQueueReverseIteratorSafe(StaticInitializer init) noexcept :
947 SharedAVLTreeIteratorSafe< Val, TreeCmp >(init) {}
948#endif // DOXYGEN_SHOULD_SKIP_THIS
949
953
957
960
962
963 // ============================================================================
965 // ============================================================================
967
970 operator=(const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from);
971
974 operator=(SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >&& from);
975
977 bool operator==(const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from) const;
978
980 bool operator!=(const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& from) const;
981
983
985 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& operator++() noexcept;
986
988
990 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& operator+=(const Size k) noexcept;
991
993
995 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& operator--() noexcept;
996
998
1000 SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp >& operator-=(const Size k) noexcept;
1001
1008 const_reference operator*() const;
1009
1011 const_pointer operator->() const;
1012
1014
1015 protected:
1019 };
1020
1022 template < typename Val, typename Priority, typename Cmp >
1023 std::ostream& operator<<(std::ostream& stream,
1024 const SortedPriorityQueue< Val, Priority, Cmp >& queue) {
1025 return stream << queue.toString();
1026 }
1027
1028
1029#ifndef DOXYGEN_SHOULD_SKIP_THIS
1030 // _static_SortedPriorityQueue_end_ is a 'constant' iterator initialized at
1031 // compile time that represents the end iterators for all the sorted priority
1032 // queues (whatever their type). This global variable avoids creating the same
1033 // iterators within every sorted priority queue instance (this would be quite
1034 // inefficient as end is precisely identical for all these queues). The same hold
1035 // for reverse and safe end iterators.
1036 // The type of _SortedPriorityQueue_end_ is a pointer to void because C++ allows
1037 // pointers to void to be cast into pointers to other types (and conversely).
1038 // This avoids the painful strict-aliasing rule warning
1040 _static_SortedPriorityQueue_end_;
1041 extern const SortedPriorityQueueReverseIterator< int, std::less< int > >
1042 _static_SortedPriorityQueue_rend_;
1043 extern const SortedPriorityQueueIteratorSafe< int, std::less< int > >
1044 _static_SortedPriorityQueue_end_safe_;
1045 extern const SortedPriorityQueueReverseIteratorSafe< int, std::less< int > >
1046 _static_SortedPriorityQueue_rend_safe_;
1047
1048 inline constexpr void* const _SortedPriorityQueue_end_
1049 = (void* const)&_static_SortedPriorityQueue_end_;
1050 inline constexpr void* const _SortedPriorityQueue_rend_
1051 = (void* const)&_static_SortedPriorityQueue_rend_;
1052 inline constexpr void* const _SortedPriorityQueue_end_safe_
1053 = (void* const)&_static_SortedPriorityQueue_end_safe_;
1054 inline constexpr void* const _SortedPriorityQueue_rend_safe_
1055 = (void* const)&_static_SortedPriorityQueue_rend_safe_;
1056#endif // DOXYGEN_SHOULD_SKIP_THIS
1057
1058} /* namespace gum */
1059
1060// always include the implementation of the templates
1062
1063#endif /* GUM_SORTED_PRIORITY_QUEUE_H */
AVL binary search tree.
Definition AVLTree.h:168
The class for generic Hash Tables.
Definition hashTable.h:637
Sorted priority queues safe (w.r.t.
~SortedPriorityQueueIteratorSafe() noexcept
destructor
SortedPriorityQueueIteratorSafe(SortedPriorityQueueIteratorSafe< Val, Priority, Cmp > &&from)
move constructor
SortedPriorityQueueIteratorSafe(const SortedPriorityQueueIteratorSafe< Val, Priority, Cmp > &from)
copy constructor
typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp TreeCmp
Types for STL compliance.
SortedPriorityQueueIteratorSafe(SortedPriorityQueue< Val, Priority, Cmp > &queue, const bool rbegin=true)
constructor for begin safe iterators
Sorted priority queue iterator.
typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp TreeCmp
~SortedPriorityQueueIterator() noexcept
destructor
SortedPriorityQueueIterator(SortedPriorityQueueIterator< Val, Priority, Cmp > &&from) noexcept
move constructor
SortedPriorityQueueIterator(const SortedPriorityQueueIterator< Val, Priority, Cmp > &from) noexcept
copy constructor
SortedPriorityQueueIterator(const SortedPriorityQueue< Val, Priority, Cmp > &queue, const bool begin=true) noexcept
constructor for begin iterators
typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp TreeCmp
Types for STL compliance.
SortedPriorityQueueReverseIteratorSafe(SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp > &&from)
move constructor
SortedPriorityQueueReverseIteratorSafe(SortedPriorityQueue< Val, Priority, Cmp > &queue, const bool rbegin=true)
constructor for rbegin safe iterators
SortedPriorityQueueReverseIteratorSafe(const SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp > &from)
copy constructor
~SortedPriorityQueueReverseIteratorSafe() noexcept
destructor
Sorted priority queue reverse iterator.
SortedPriorityQueueReverseIterator(SortedPriorityQueueReverseIterator< Val, Priority, Cmp > &&from) noexcept
move constructor
typename SortedPriorityQueue< Val, Priority, Cmp >::TreeCmp TreeCmp
Types for STL compliance.
~SortedPriorityQueueReverseIterator() noexcept
destructor
SortedPriorityQueueReverseIterator(const SortedPriorityQueueReverseIterator< Val, Priority, Cmp > &from) noexcept
copy constructor
SortedPriorityQueueReverseIterator(const SortedPriorityQueue< Val, Priority, Cmp > &queue, const bool rbegin=true) noexcept
constructor for rbegin iterators
A priority queue in which we can iterate over the elements from the top to bottom or conversely.
iterator_safe beginSafe()
returns a new safe iterator pointing to the minimal element of the tree
Val * pointer
Types for STL compliance.
SortedPriorityQueueReverseIteratorSafe< Val, Priority, Cmp > reverse_iterator_safe
Types for STL compliance.
Size capacity() const noexcept
Returns the size of the internal structure storing the priority queue.
SortedPriorityQueueIteratorSafe< Val, Priority, Cmp > iterator_safe
Types for STL compliance.
const_reference emplace(Args &&... args)
Emplace a new element into the priority queue.
void eraseTop()
Removes the top of the priority queue (but does not return it).
value_type popTop()
Alias of pop.
bool empty() const noexcept
Indicates whether the priority queue is empty.
HashTable< AVLTreeNode< Val >, Priority > _nodes_
A hashtable for quickly finding the elements by their value.
SharedAVLTree< Val, TreeCmp > _tree_
A binary search tree storing all the values of the queue.
const Val & top() const
returns the element at the top of the sorted priority queue
void clear()
Removes all the elements from the queue.
~SortedPriorityQueue()
Class destructor.
AVLNode & getNode_(const Val &val) const
returns the node in the hash table corresponding to a given value
constexpr const iterator_safe & endSafe() const
returns a safe iterator pointing just after the maximal element
constexpr const reverse_iterator & rend() const
returns an iterator pointing just before the minimal element
void resize(Size new_size)
Changes the size of the internal structure storing the priority queue.
std::ptrdiff_t difference_type
Types for STL compliance.
void eraseBottom()
Removes the bottom of the priority queue (but does not return it).
TreeCmp _tree_cmp_
Comparison function.
SortedPriorityQueue< Val, Priority, Cmp > & operator=(const SortedPriorityQueue< Val, Priority, Cmp > &from)
Copy operator.
SortedPriorityQueueIterator< Val, Priority, Cmp > iterator
Types for STL compliance.
Val value_type
Types for STL compliance.
SortedPriorityQueue(std::initializer_list< std::pair< Val, Priority > > list)
Initializer list constructor.
SortedPriorityQueue(SortedPriorityQueue< Val, Priority, Cmp > &&from) noexcept
Move constructor.
const Val & const_reference
Types for STL compliance.
reverse_iterator_safe rbeginSafe()
returns a safe iterator pointing to the maximal element of the tree
const Priority & priority(const Val &elt) const
Returns the priority of an instance of the value passed in argument.
value_type pop()
Removes the top element from the priority queue and return it.
Val & reference
Types for STL compliance.
SortedPriorityQueue< Val, Priority, Cmp > & operator=(SortedPriorityQueue< Val, Priority, Cmp > &&from) noexcept
Move operator.
SortedPriorityQueue(Cmp compare=Cmp(), Size capacity=GUM_PRIORITY_QUEUE_DEFAULT_CAPACITY)
Basic constructor.
std::string toString() const
Displays the content of the queue.
SortedPriorityQueue(const SortedPriorityQueue< Val, Priority, Cmp > &from)
Copy constructor.
reverse_iterator rbegin() const
returns a new iterator pointing to the maximal element of the tree
constexpr const iterator & end() const
returns an iterator pointing just after the maximal element
const Val * const_pointer
Types for STL compliance.
value_type popBottom()
Removes the bottom element from the priority queue and return it.
Size size() const noexcept
Returns the number of elements in the priority queue.
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
const_reference insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
const Priority & bottomPriority() const
Returns the priority of the bottom element.
void setPriority(const Val &elt, const Priority &new_priority)
Modifies the priority of each instance of a given element.
bool contains(const Val &val) const noexcept
Indicates whether the priority queue contains a given value.
SortedPriorityQueueReverseIterator< Val, Priority, Cmp > reverse_iterator
Types for STL compliance.
constexpr const reverse_iterator_safe & rendSafe() const
returns a safe iterator pointing just before the minimal element
const Val & bottom() const
returns the element at the bottom of the sorted priority queue
iterator begin() const
returns a new iterator pointing to the minimal element of the tree
const Priority & topPriority() const
Returns the priority of the top element.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
priority queues (in which an element cannot appear more than once)
#define GUM_PRIORITY_QUEUE_DEFAULT_CAPACITY
AVL binary search trees that do not possess their own nodes.
static constexpr Size default_size
The default number of slots in hashtables.
Definition hashTable.h:101