24#ifndef PRIORITY_QUEUE_INCLUDED
25#define PRIORITY_QUEUE_INCLUDED
39#if defined(EXTRA_CODE_FOR_UNIT_TESTING)
45class PriorityQueueTest;
101template <
typename T,
typename Container = std::vector<T>,
102 typename Less = std::less<
typename Container::value_type>,
103 typename Marker = NoopMarker<T>>
110 typedef typename container_type::iterator
iterator;
158 }
while (largest != i);
166 size_t parent_idx =
parent(i);
190 const Marker &marker = Marker())
194 template <
typename Input_iterator>
196 Less
const &less = Less(),
198 const Marker &marker = Marker())
243 }
catch (std::bad_alloc
const &) {
421 }
catch (std::bad_alloc
const &) {
432#if defined(EXTRA_CODE_FOR_UNIT_TESTING)
433template <
class T,
class Container,
class Less,
class Marker>
439 for (size_type i = 0; i < pq.
size(); i++) {
446template <
class T,
class Container,
class Less,
class Marker>
448 std::stringstream &ss,
453 for (size_type i = 0; i < pq.
size(); i++) {
Definition: priority_queue.h:49
void operator()(size_t, T *) const
Definition: priority_queue.h:51
Implements a priority queue using a vector-based max-heap.
Definition: priority_queue.h:104
value_type & operator[](size_type i)
Returns a reference to the i-th element in the underlying container.
Definition: priority_queue.h:350
static size_type parent(size_type i)
Definition: priority_queue.h:121
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:195
void increase_key(size_type i, value_type const &x)
Definition: priority_queue.h:181
value_type & top()
Returns a reference to the top element of the priority queue.
Definition: priority_queue.h:229
size_type capacity() const
Returns the capacity of the internal container.
Definition: priority_queue.h:409
void swap(Priority_queue &other)
Swaps the contents of two priority queues.
Definition: priority_queue.h:368
void clear()
Clears the priority queue.
Definition: priority_queue.h:403
void sort()
Sorts the elements of the priority queue according to the strict partial ordering defined by the obje...
Definition: priority_queue.h:391
container_type::allocator_type allocator_type
Definition: priority_queue.h:112
Marker m_marker
Definition: priority_queue.h:429
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:274
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:294
static size_type right(size_type i)
Definition: priority_queue.h:132
container_type::iterator iterator
Definition: priority_queue.h:110
void heapify(size_type i)
Definition: priority_queue.h:161
friend class priority_queue_unittest::PriorityQueueTest
Definition: priority_queue.h:114
void update(size_type i)
Assumes that the i-th element's value has changed and rebuilds the priority queue.
Definition: priority_queue.h:319
void delete_elements()
Clears the priority queue, but deletes all elements first.
Definition: priority_queue.h:406
container_type::const_iterator const_iterator
Definition: priority_queue.h:111
void reverse_heapify(size_type i)
Definition: priority_queue.h:163
bool is_valid() const
Returns true if the priority queue has the heap property.
Definition: priority_queue.h:374
container_type::value_type value_type
Definition: priority_queue.h:108
static size_type left(size_type i)
Definition: priority_queue.h:127
Less less_type
Definition: priority_queue.h:107
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:284
container_type::size_type size_type
Definition: priority_queue.h:109
iterator begin()
Returns an iterator to the first element of the underlying container.
Definition: priority_queue.h:362
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:188
value_type const & top() const
Returns a const reference to the top element of the priority queue.
Definition: priority_queue.h:223
iterator end()
Returns an iterator to the end element of the underlying container.
Definition: priority_queue.h:365
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:344
void decrease(size_type i)
Assumes that the i-th element's value has decreased and rebuilds the priority queue.
Definition: priority_queue.h:313
container_type m_container
Definition: priority_queue.h:428
void increase(size_type i)
Assumes that the i-th element's value has increased and rebuilds the priority queue.
Definition: priority_queue.h:307
Container container_type
Definition: priority_queue.h:106
const_iterator end() const
Returns a const iterator to the end element of the underlying container.
Definition: priority_queue.h:359
void decrease_key(size_type i, value_type const &x)
Definition: priority_queue.h:175
void remove(size_type i)
Removes the element at position i from the priority queue.
Definition: priority_queue.h:256
bool reserve(size_type n)
Reserves space for array elements.
Definition: priority_queue.h:417
bool empty() const
Returns true if the priority queue is empty.
Definition: priority_queue.h:341
void pop()
Pops the top-most element in the priority queue.
Definition: priority_queue.h:253
size_type size() const
Returns the number of elements of the priority queue.
Definition: priority_queue.h:338
void update_top()
Assumes that the top element's value has changed and rebuilds the priority queue.
Definition: priority_queue.h:332
void assign(const container_type &container)
Constructs a heap based on input argument.
Definition: priority_queue.h:204
void heapify(size_type i, size_type last)
Definition: priority_queue.h:136
bool push(value_type const &x)
Inserts an element in the priority queue.
Definition: priority_queue.h:240
void build_heap()
Constructs a heap based on container contents.
Definition: priority_queue.h:213
Less Base
Definition: priority_queue.h:118
const_iterator begin() const
Returns a const iterator to the first element of the underlying container.
Definition: priority_queue.h:356
ostream & operator<<(ostream &os, const Datetime &)
Definition: logger.cc:35
uint16_t value_type
Definition: vt100.h:184
Definition: atomics_array.h:39
Definition: priority_queue.h:44
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:122
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:642
void delete_container_pointers(Container_type &container)
Clears a container, but deletes all objects that the elements point to first.
Definition: template_utils.h:44
int n
Definition: xcom_base.cc:509