|
| Priority_queue (Less const &less=Less(), const allocator_type &alloc=allocator_type(), const Marker &marker=Marker()) |
| Constructs an empty priority queue. More...
|
|
template<typename Input_iterator > |
| Priority_queue (Input_iterator first, Input_iterator beyond, Less const &less=Less(), const allocator_type &alloc=allocator_type(), const Marker &marker=Marker()) |
| Constructs a heap of the objects between first and beyond. More...
|
|
void | assign (const container_type &container) |
| Constructs a heap based on input argument. More...
|
|
void | build_heap () |
| Constructs a heap based on container contents. More...
|
|
value_type const & | top () const |
| Returns a const reference to the top element of the priority queue. More...
|
|
value_type & | top () |
| Returns a reference to the top element of the priority queue. More...
|
|
bool | push (value_type const &x) |
| Inserts an element in the priority queue. More...
|
|
void | pop () |
| Pops the top-most element in the priority queue. More...
|
|
void | remove (size_type i) |
| Removes the element at position i from the priority queue. More...
|
|
void | decrease (size_type i, value_type const &x) |
| Decreases the priority of the element at position i, where the new priority is x. More...
|
|
void | increase (size_type i, value_type const &x) |
| Increases the priority of the element at position i, where the new priority is x. More...
|
|
void | update (size_type i, value_type const &x) |
| Changes the priority of the element at position i, where the new priority is x. More...
|
|
void | increase (size_type i) |
| Assumes that the i-th element's value has increased and rebuilds the priority queue. More...
|
|
void | decrease (size_type i) |
| Assumes that the i-th element's value has decreased and rebuilds the priority queue. More...
|
|
void | update (size_type i) |
| Assumes that the i-th element's value has changed and rebuilds the priority queue. More...
|
|
void | update_top () |
| Assumes that the top element's value has changed and rebuilds the priority queue. More...
|
|
size_type | size () const |
| Returns the number of elements of the priority queue. More...
|
|
bool | empty () const |
| Returns true if the priority queue is empty. More...
|
|
value_type const & | operator[] (size_type i) const |
| Returns a const reference to the i-th element in the underlying container. More...
|
|
value_type & | operator[] (size_type i) |
| Returns a reference to the i-th element in the underlying container. More...
|
|
const_iterator | begin () const |
| Returns a const iterator to the first element of the underlying container. More...
|
|
const_iterator | end () const |
| Returns a const iterator to the end element of the underlying container. More...
|
|
iterator | begin () |
| Returns an iterator to the first element of the underlying container. More...
|
|
iterator | end () |
| Returns an iterator to the end element of the underlying container. More...
|
|
void | swap (Priority_queue &other) |
| Swaps the contents of two priority queues. More...
|
|
bool | is_valid () const |
| Returns true if the priority queue has the heap property. More...
|
|
void | sort () |
| Sorts the elements of the priority queue according to the strict partial ordering defined by the object of type Less passed to the priority queue. More...
|
|
void | clear () |
| Clears the priority queue. More...
|
|
void | delete_elements () |
| Clears the priority queue, but deletes all elements first. More...
|
|
size_type | capacity () const |
| Returns the capacity of the internal container. More...
|
|
bool | reserve (size_type n) |
| Reserves space for array elements. More...
|
|
template<typename T, typename Container = std::vector<T>, typename Less = std::less<typename Container::value_type>, typename Marker = NoopMarker<T>>
class Priority_queue< T, Container, Less, Marker >
Implements a priority queue using a vector-based max-heap.
A priority queue is a container specifically designed such that its first element is always the greatest of the elements it contains, according to some strict weak ordering criterion.
For object locality, the implementation is vector-based, rather than node-based.
The priority queue is mutable, which means that the priority of an element can be changed. See increase/decrease/update member functions. The typical use case is to change the value/priority of the root node.
We provide iterators, which can be used to visit all elements. Iterators do not visit queue elements in priority order. Iterators should not be used to change the priority of elements.
The underlying container must be constructible from an iterator range, should provide const and non-const random access iterators to access its elements, as well as the following operations:
- size()
- empty()
- push_back()
- pop_back()
- swap()
- clear()
- capacity()
- reserve()
- max_size()
- Template Parameters
-
T | Type of the elements of the priority queue. |
Container | Type of the underlying container object where elements are stored. Its value_type shall be T. |
Less | A binary predicate that takes two elements (of type T) and returns a bool. The expression less(a,b), where less is an object of this type and a and b are elements in the container, shall return true if a is considered to go before b in the strict weak ordering the function defines. |
Marker | A functor, with signature void operator()(size_t, T *), that gets called whenever an element gets a new position in the queue (including initial insert, but excluding removals). The marker can then store the element's position somewhere, for later calls to update() as needed. |