29 #ifndef GUM_MULTI_PRIORITY_QUEUE_H 30 #define GUM_MULTI_PRIORITY_QUEUE_H 33 #include <initializer_list> 39 #include <agrum/agrum.h> 40 #include <agrum/tools/core/hashTable.h> 44 #define GUM_MULTIPLE_PRIORITY_QUEUE_DEFAULT_CAPACITY 10
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS 48 template <
typename Val,
typename Priority,
typename Cmp,
typename Alloc >
49 class MultiPriorityQueue;
51 template <
typename Val,
typename Priority,
typename Cmp,
typename Alloc >
52 std::ostream& operator<<(std::ostream&,
53 const MultiPriorityQueue< Val, Priority, Cmp, Alloc >&);
122 template <
typename Val,
123 typename Priority =
int,
124 typename Cmp = std::less< Priority >,
125 typename Alloc = std::allocator< Val > >
126 class MultiPriorityQueue {
128 template <
typename V,
typename P,
typename C,
typename A >
129 friend class MultiPriorityQueue;
134 using value_type = Val;
135 using reference = Val&;
136 using const_reference =
const Val&;
137 using pointer = Val*;
138 using const_pointer =
const Val*;
139 using difference_type = std::ptrdiff_t;
140 using allocator_type = Alloc;
144 using IndexAlloc =
typename Alloc::
template rebind<
145 std::pair< Val, std::vector< Size > > >::other;
149 typename Alloc::
template rebind< std::pair< Priority,
const Val* > >::other;
165 explicit MultiPriorityQueue(Cmp compare = Cmp(),
177 explicit MultiPriorityQueue(
178 std::initializer_list< std::pair< Val, Priority > > list);
185 const MultiPriorityQueue< Val, Priority, Cmp, Alloc >& from);
193 template <
typename OtherAlloc >
195 const MultiPriorityQueue< Val, Priority, Cmp, OtherAlloc >& from);
201 MultiPriorityQueue(MultiPriorityQueue< Val, Priority, Cmp, Alloc >&& from);
206 ~MultiPriorityQueue();
224 MultiPriorityQueue< Val, Priority, Cmp, Alloc >&
225 operator=(
const MultiPriorityQueue< Val, Priority, Cmp, Alloc >& from);
238 template <
typename OtherAlloc >
239 MultiPriorityQueue< Val, Priority, Cmp, Alloc >&
240 operator=(
const MultiPriorityQueue< Val, Priority, Cmp, OtherAlloc >& from);
246 MultiPriorityQueue< Val, Priority, Cmp, Alloc >&
247 operator=(MultiPriorityQueue< Val, Priority, Cmp, Alloc >&& from);
256 const Val& operator[](Size index_elt)
const;
268 Size size()
const noexcept;
274 bool empty()
const noexcept;
281 bool contains(
const Val& val)
const;
288 const Val& top()
const;
294 const Priority& topPriority()
const;
314 Size insert(
const Val& val,
const Priority& priority);
327 Size insert(Val&& val, Priority&& priority);
339 template <
typename... Args >
340 Size emplace(Args&&... args);
368 void eraseByPos(Size index);
382 void erase(
const Val& val);
393 Size setPriorityByPos(Size index,
const Priority& new_priority);
404 Size setPriorityByPos(Size index, Priority&& new_priority);
412 void setPriority(
const Val& elt,
const Priority& new_priority);
426 const Priority& priority(
const Val& elt)
const;
444 const HashTable< Val, std::vector< Size > >& allValues()
const;
450 std::string toString()
const;
464 Size capacity()
const noexcept;
473 void resize(Size new_size);
479 std::vector< std::pair< Priority,
const Val* >, HeapAlloc > heap__;
482 HashTable< Val, std::vector< Size >, IndexAlloc > indices__;
485 Size nb_elements__{0};
494 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 495 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 496 extern template class gum::MultiPriorityQueue< std::string >;
499 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 500 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 501 extern template class gum::MultiPriorityQueue<
int,
int >;
507 #include <agrum/tools/core/multiPriorityQueue_tpl.h> #define GUM_MULTIPLE_PRIORITY_QUEUE_DEFAULT_CAPACITY