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&,
const MultiPriorityQueue< Val, Priority, Cmp, Alloc >&);
121 template <
typename Val,
122 typename Priority =
int,
123 typename Cmp = std::less< Priority >,
124 typename Alloc = std::allocator< Val > >
125 class MultiPriorityQueue {
127 template <
typename V,
typename P,
typename C,
typename A >
128 friend class MultiPriorityQueue;
133 using value_type = Val;
134 using reference = Val&;
135 using const_reference =
const Val&;
136 using pointer = Val*;
137 using const_pointer =
const Val*;
138 using difference_type = std::ptrdiff_t;
139 using allocator_type = Alloc;
144 typename Alloc::
template rebind< std::pair< Val, std::vector< Size > > >::other;
147 using HeapAlloc =
typename Alloc::
template rebind< std::pair< Priority,
const Val* > >::other;
163 explicit MultiPriorityQueue(Cmp compare = Cmp(),
174 explicit MultiPriorityQueue(std::initializer_list< std::pair< Val, Priority > > list);
180 MultiPriorityQueue(
const MultiPriorityQueue< Val, Priority, Cmp, Alloc >& from);
188 template <
typename OtherAlloc >
189 MultiPriorityQueue(
const MultiPriorityQueue< Val, Priority, Cmp, OtherAlloc >& from);
195 MultiPriorityQueue(MultiPriorityQueue< Val, Priority, Cmp, Alloc >&& from);
200 ~MultiPriorityQueue();
218 MultiPriorityQueue< Val, Priority, Cmp, Alloc >&
219 operator=(
const MultiPriorityQueue< Val, Priority, Cmp, Alloc >& from);
232 template <
typename OtherAlloc >
233 MultiPriorityQueue< Val, Priority, Cmp, Alloc >&
234 operator=(
const MultiPriorityQueue< Val, Priority, Cmp, OtherAlloc >& from);
240 MultiPriorityQueue< Val, Priority, Cmp, Alloc >&
241 operator=(MultiPriorityQueue< Val, Priority, Cmp, Alloc >&& from);
250 const Val& operator[](Size index_elt)
const;
262 Size size()
const noexcept;
268 bool empty()
const noexcept;
275 bool contains(
const Val& val)
const;
282 const Val& top()
const;
288 const Priority& topPriority()
const;
308 Size insert(
const Val& val,
const Priority& priority);
321 Size insert(Val&& val, Priority&& priority);
333 template <
typename... Args >
334 Size emplace(Args&&... args);
362 void eraseByPos(Size index);
376 void erase(
const Val& val);
387 Size setPriorityByPos(Size index,
const Priority& new_priority);
398 Size setPriorityByPos(Size index, Priority&& new_priority);
406 void setPriority(
const Val& elt,
const Priority& new_priority);
420 const Priority& priority(
const Val& elt)
const;
438 const HashTable< Val, std::vector< Size > >& allValues()
const;
444 std::string toString()
const;
458 Size capacity()
const noexcept;
467 void resize(Size new_size);
473 std::vector< std::pair< Priority,
const Val* >, HeapAlloc > _heap_;
476 HashTable< Val, std::vector< Size >, IndexAlloc > _indices_;
479 Size _nb_elements_{0};
488 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 489 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 490 extern template class gum::MultiPriorityQueue< std::string >;
493 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 494 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 495 extern template class gum::MultiPriorityQueue<
int,
int >;
501 #include <agrum/tools/core/multiPriorityQueue_tpl.h> #define GUM_MULTIPLE_PRIORITY_QUEUE_DEFAULT_CAPACITY