49#ifndef GUM_MULTI_PRIORITY_QUEUE_H
50#define GUM_MULTI_PRIORITY_QUEUE_H
62#include <initializer_list>
66#define GUM_MULTIPLE_PRIORITY_QUEUE_DEFAULT_CAPACITY 10
68#ifndef DOXYGEN_SHOULD_SKIP_THIS
70 template <
typename Val,
typename Priority,
typename Cmp >
71 class MultiPriorityQueue;
73 template <
typename Val,
typename Priority,
typename Cmp >
74 std::ostream&
operator<<(std::ostream&,
const MultiPriorityQueue< Val, Priority, Cmp >&);
142 template <
typename Val,
typename Priority =
int,
typename Cmp = std::less< Priority > >
181 explicit MultiPriorityQueue(std::initializer_list< std::pair< Val, Priority > > list);
251 bool empty() const noexcept;
258 bool contains(const Val& val) const;
265 const Val&
top() const;
316 template < typename... Args >
359 void erase(const Val& val);
389 void setPriority(const Val& elt, const Priority& new_priority);
403 const Priority&
priority(const Val& elt) const;
471#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
The class for generic Hash Tables.
A MultiPriorityQueue is a heap in which each element has a mutable priority and duplicates are allowe...
Cmp _cmp_
Comparison function.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
Size _nb_elements_
The number of elements in the heap.
void resize(Size new_size)
Changes the size of the internal structure storing the priority queue.
const HashTable< Val, std::vector< Size > > & allValues() const
Returns a gum::HashTable the keys of which are the values stored in the queue.
const Priority & topPriority() const
Returns the priority of the top element.
Size size() const noexcept
Returns the number of elements in the priority queue.
Size capacity() const noexcept
Return the size of the internal structure storing the priority queue.
bool empty() const noexcept
Indicates whether the priority queue is empty.
Val value_type
types for STL compliance
void eraseByPos(Size index)
Removes the element at position "index" from the priority queue.
const Val & operator[](Size index_elt) const
Returns the element at index "index_elt" from the priority queue.
std::vector< std::pair< Priority, const Val * > > _heap_
An array storing all the elements of the heap as well as their score.
void setPriority(const Val &elt, const Priority &new_priority)
Modifies the priority of each instance of a given element.
const Val & top() const
Returns the element at the top of the priority queue.
Val pop()
Removes the top element from the priority queue and return it.
const Val & const_reference
types for STL compliance
MultiPriorityQueue< Val, Priority, Cmp > & operator=(const MultiPriorityQueue< Val, Priority, Cmp > &from)
Copy operator.
const Priority & priority(const Val &elt) const
Returns the priority of an instance of the value passed in argument.
std::ptrdiff_t difference_type
types for STL compliance
Size setPriorityByPos(Size index, const Priority &new_priority)
Modifies the priority of the element at position "index" of the queue.
const Val * const_pointer
types for STL compliance
bool contains(const Val &val) const
Indicates whether the priority queue contains a given value.
HashTable< Val, std::vector< Size > > _indices_
A hashtable for quickly finding the elements by their value.
~MultiPriorityQueue()
Class destructor.
void eraseTop()
Removes the top of the priority queue (but does not return it).
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
std::string toString() const
Displays the content of the queue.
void clear()
Removes all the elements from the queue.
Val * pointer
types for STL compliance
Size emplace(Args &&... args)
Emplace a new element into the priority queue.
Val & reference
types for STL compliance
MultiPriorityQueue(Cmp compare=Cmp(), Size capacity=GUM_MULTIPLE_PRIORITY_QUEUE_DEFAULT_CAPACITY)
Basic constructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Class hash tables iterators.
#define GUM_MULTIPLE_PRIORITY_QUEUE_DEFAULT_CAPACITY
Template implementations of multi priority queues.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree