23#ifndef PRIORITY_QUEUE_INCLUDED
24#define PRIORITY_QUEUE_INCLUDED
38#if defined(EXTRA_CODE_FOR_UNIT_TESTING)
44class PriorityQueueTest;
100template <
typename T,
typename Container = std::vector<T>,
101 typename Less = std::less<
typename Container::value_type>,
102 typename Marker = NoopMarker<T>>
109 typedef typename container_type::iterator
iterator;
157 }
while (largest != i);
165 size_t parent_idx =
parent(i);
189 const Marker &marker = Marker())
193 template <
typename Input_iterator>
195 Less
const &less = Less(),
197 const Marker &marker = Marker())
242 }
catch (std::bad_alloc
const &) {
420 }
catch (std::bad_alloc
const &) {
431#if defined(EXTRA_CODE_FOR_UNIT_TESTING)
432template <
class T,
class Container,
class Less,
class Marker>
438 for (size_type i = 0; i < pq.
size(); i++) {
445template <
class T,
class Container,
class Less,
class Marker>
447 std::stringstream &ss,
452 for (size_type i = 0; i < pq.
size(); i++) {
Definition: priority_queue.h:48
void operator()(size_t, T *) const
Definition: priority_queue.h:50
Implements a priority queue using a vector-based max-heap.
Definition: priority_queue.h:103
value_type & operator[](size_type i)
Returns a reference to the i-th element in the underlying container.
Definition: priority_queue.h:349
static size_type parent(size_type i)
Definition: priority_queue.h:120
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.
Definition: priority_queue.h:194
void increase_key(size_type i, value_type const &x)
Definition: priority_queue.h:180
value_type & top()
Returns a reference to the top element of the priority queue.
Definition: priority_queue.h:228
size_type capacity() const
Returns the capacity of the internal container.
Definition: priority_queue.h:408
void swap(Priority_queue &other)
Swaps the contents of two priority queues.
Definition: priority_queue.h:367
void clear()
Clears the priority queue.
Definition: priority_queue.h:402
void sort()
Sorts the elements of the priority queue according to the strict partial ordering defined by the obje...
Definition: priority_queue.h:390
container_type::allocator_type allocator_type
Definition: priority_queue.h:111
Marker m_marker
Definition: priority_queue.h:428
void decrease(size_type i, value_type const &x)
Decreases the priority of the element at position i, where the new priority is x.
Definition: priority_queue.h:273
void update(size_type i, value_type const &x)
Changes the priority of the element at position i, where the new priority is x.
Definition: priority_queue.h:293
static size_type right(size_type i)
Definition: priority_queue.h:131
container_type::iterator iterator
Definition: priority_queue.h:109
void heapify(size_type i)
Definition: priority_queue.h:160
friend class priority_queue_unittest::PriorityQueueTest
Definition: priority_queue.h:113
void update(size_type i)
Assumes that the i-th element's value has changed and rebuilds the priority queue.
Definition: priority_queue.h:318
void delete_elements()
Clears the priority queue, but deletes all elements first.
Definition: priority_queue.h:405
container_type::const_iterator const_iterator
Definition: priority_queue.h:110
void reverse_heapify(size_type i)
Definition: priority_queue.h:162
bool is_valid() const
Returns true if the priority queue has the heap property.
Definition: priority_queue.h:373
container_type::value_type value_type
Definition: priority_queue.h:107
static size_type left(size_type i)
Definition: priority_queue.h:126
Less less_type
Definition: priority_queue.h:106
void increase(size_type i, value_type const &x)
Increases the priority of the element at position i, where the new priority is x.
Definition: priority_queue.h:283
container_type::size_type size_type
Definition: priority_queue.h:108
iterator begin()
Returns an iterator to the first element of the underlying container.
Definition: priority_queue.h:361
Priority_queue(Less const &less=Less(), const allocator_type &alloc=allocator_type(), const Marker &marker=Marker())
Constructs an empty priority queue.
Definition: priority_queue.h:187
value_type const & top() const
Returns a const reference to the top element of the priority queue.
Definition: priority_queue.h:222
iterator end()
Returns an iterator to the end element of the underlying container.
Definition: priority_queue.h:364
value_type const & operator[](size_type i) const
Returns a const reference to the i-th element in the underlying container.
Definition: priority_queue.h:343
void decrease(size_type i)
Assumes that the i-th element's value has decreased and rebuilds the priority queue.
Definition: priority_queue.h:312
container_type m_container
Definition: priority_queue.h:427
void increase(size_type i)
Assumes that the i-th element's value has increased and rebuilds the priority queue.
Definition: priority_queue.h:306
Container container_type
Definition: priority_queue.h:105
const_iterator end() const
Returns a const iterator to the end element of the underlying container.
Definition: priority_queue.h:358
void decrease_key(size_type i, value_type const &x)
Definition: priority_queue.h:174
void remove(size_type i)
Removes the element at position i from the priority queue.
Definition: priority_queue.h:255
bool reserve(size_type n)
Reserves space for array elements.
Definition: priority_queue.h:416
bool empty() const
Returns true if the priority queue is empty.
Definition: priority_queue.h:340
void pop()
Pops the top-most element in the priority queue.
Definition: priority_queue.h:252
size_type size() const
Returns the number of elements of the priority queue.
Definition: priority_queue.h:337
void update_top()
Assumes that the top element's value has changed and rebuilds the priority queue.
Definition: priority_queue.h:331
void assign(const container_type &container)
Constructs a heap based on input argument.
Definition: priority_queue.h:203
void heapify(size_type i, size_type last)
Definition: priority_queue.h:135
bool push(value_type const &x)
Inserts an element in the priority queue.
Definition: priority_queue.h:239
void build_heap()
Constructs a heap based on container contents.
Definition: priority_queue.h:212
Less Base
Definition: priority_queue.h:117
const_iterator begin() const
Returns a const iterator to the first element of the underlying container.
Definition: priority_queue.h:355
ostream & operator<<(ostream &os, const Datetime &)
Definition: logger.cc:34
uint16_t value_type
Definition: vt100.h:183
Definition: atomics_array.h:38
Definition: priority_queue.h:43
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:121
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:611
void delete_container_pointers(Container_type &container)
Clears a container, but deletes all objects that the elements point to first.
Definition: template_utils.h:43
int n
Definition: xcom_base.cc:508