KTL
|
A priority queue implemented as a binary heap. More...
#include <binary_heap.h>
Public Types | |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef std::reverse_iterator< T * > | reverse_iterator |
typedef std::reverse_iterator< const T * > | const_reverse_iterator |
Public Member Functions | |
binary_heap (const Comp &comp=Comp()) noexcept | |
Construct the binary heap with the given comparator. More... | |
binary_heap (const Alloc &allocator, const Comp &comp=Comp()) noexcept | |
Construct the binary heap with the given allocator and comparator. More... | |
binary_heap (size_t capacity, const Comp &comp=Comp()) noexcept | |
Construct the binary heap with the given comparator and an initial capacity. More... | |
binary_heap (size_t capacity, const Alloc &allocator, const Comp &comp=Comp()) noexcept | |
Construct the binary heap with the given allocator, comparator and an initial capacity. More... | |
binary_heap (std::initializer_list< T > initializer, const Comp &comp=Comp()) | |
Construct the binary heap with the given comparator and an initial set of values. More... | |
binary_heap (std::initializer_list< T > initializer, const Alloc &allocator, const Comp &comp=Comp()) | |
Construct the binary heap with the given allocator, comparator and an initial set of values. More... | |
binary_heap (const binary_heap &other) noexcept(std::is_nothrow_copy_constructible_v< T >) | |
binary_heap (binary_heap &&other) noexcept(std::is_nothrow_move_constructible_v< T >) | |
binary_heap (const binary_heap &other, const Alloc &allocator) noexcept(std::is_nothrow_copy_constructible_v< T >) | |
binary_heap (binary_heap &&other, const Alloc &allocator) noexcept(std::is_nothrow_move_constructible_v< T >) | |
~binary_heap () | |
binary_heap & | operator= (const binary_heap &other) noexcept(std::is_nothrow_copy_assignable_v< T >) |
binary_heap & | operator= (binary_heap &&other) noexcept(std::is_nothrow_move_assignable_v< T >) |
iterator | begin () noexcept |
const_iterator | begin () const noexcept |
iterator | end () noexcept |
const_iterator | end () const noexcept |
reverse_iterator | rbegin () noexcept |
const_reverse_iterator | rbegin () const noexcept |
reverse_iterator | rend () noexcept |
const_reverse_iterator | rend () const noexcept |
iterator | data () noexcept |
Returns an iterator to the start of the heap. More... | |
const_iterator | data () const noexcept |
Returns a const iterator to the start of the heap. More... | |
size_t | size () const noexcept |
Returns the current size of the heap. More... | |
size_t | capacity () const noexcept |
Returns the current capacity of the heap. More... | |
bool | empty () const noexcept |
Returns true if the heap has no elements. More... | |
void | reserve (size_t n) noexcept |
Reserves the capacity of the heap to n , without initializing any elements. More... | |
template<typename V > | |
iterator | insert (V &&value) noexcept |
Inserts a new element into the heap via perfect forwarding. More... | |
T & | peek () noexcept |
Peeks at the root element (lowest or highest, depending on min or max heap) and returns a reference to it. More... | |
T | pop () noexcept |
Removes the root element (lowest or highest, depending on min or max heap) and returns it. More... | |
iterator | find (const T &value) const noexcept |
Returns an iterator to the element index . Takes O(n) time. More... | |
void | clear () noexcept |
Clear all elements in the heap, destroying each element. More... | |
A priority queue implemented as a binary heap.
T | The type to use. Must be move constructible and move assignable |
Comp | The comparison function. Usually std::greater<T> or std::less<T> |
Alloc | The type of allocoator to use |
typedef const T* ktl::binary_heap< T, Comp, Alloc >::const_iterator |
typedef std::reverse_iterator<const T*> ktl::binary_heap< T, Comp, Alloc >::const_reverse_iterator |
typedef T* ktl::binary_heap< T, Comp, Alloc >::iterator |
typedef std::reverse_iterator<T*> ktl::binary_heap< T, Comp, Alloc >::reverse_iterator |
|
inlinenoexcept |
Construct the binary heap with the given comparator.
comp | The comparator to use. Will be default constructed if unspecified |
|
inlinenoexcept |
Construct the binary heap with the given allocator and comparator.
allocator | The allocator to use |
comp | The comparator to use. Will be default constructed if unspecified |
|
inlineexplicitnoexcept |
Construct the binary heap with the given comparator and an initial capacity.
capacity | The initial capacity to use |
comp | The comparator to use. Will be default constructed if unspecified |
|
inlineexplicitnoexcept |
Construct the binary heap with the given allocator, comparator and an initial capacity.
capacity | The initial capacity to use |
allocator | The allocator to use. Will be default constructed if unspecified |
comp | The comparator to use. Will be default constructed if unspecified |
|
inline |
Construct the binary heap with the given comparator and an initial set of values.
initializer | A list of values to insert into the binary heap |
comp | The comparator to use. Will be default constructed if unspecified |
|
inline |
Construct the binary heap with the given allocator, comparator and an initial set of values.
initializer | A list of values to insert into the binary heap |
allocator | The allocator to use. Will be default constructed if unspecified |
comp | The comparator to use. Will be default constructed if unspecified |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Returns the current capacity of the heap.
|
inlinenoexcept |
Clear all elements in the heap, destroying each element.
|
inlinenoexcept |
Returns a const iterator to the start of the heap.
|
inlinenoexcept |
Returns an iterator to the start of the heap.
|
inlinenoexcept |
Returns true if the heap has no elements.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Returns an iterator to the element index
. Takes O(n) time.
value | The value to return the iterator of. |
|
inlinenoexcept |
Inserts a new element into the heap via perfect forwarding.
V | The type to insert. |
value | The element to insert into the heap. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Peeks at the root element (lowest or highest, depending on min or max heap) and returns a reference to it.
|
inlinenoexcept |
Removes the root element (lowest or highest, depending on min or max heap) and returns it.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Reserves the capacity of the heap to n
, without initializing any elements.
n | The minimum capacity of the heap. |
|
inlinenoexcept |
Returns the current size of the heap.