|
Flow
Documentation for the Flow C++ Library
|
A binary min-heap container. Supports custom comparator and allocator. More...
#include <flow_binary_heap.h>
Public Types | |
| using | value_type = T |
| using | reference = T& |
| using | const_reference = const T& |
| using | pointer = T* |
| using | const_pointer = const T* |
| using | iterator = T* |
| using | const_iterator = const T* |
| using | difference_type = std::ptrdiff_t |
| using | container_type = Vector<T, Allocator> |
| using | allocator_type = container_type::allocator_type |
Public Member Functions | |
| constexpr | BinaryHeap () noexcept(noexcept(container_type()) &&noexcept(Compare())) |
| Constructs an empty heap with default comparator and allocator. Comparator must be default initializable. | |
| constexpr | BinaryHeap (const allocator_type &allocator) noexcept(noexcept(container_type(allocator)) &&noexcept(Compare())) |
| Constructs an empty heap with a specific allocator. Comparator must be default initializable. | |
| constexpr | BinaryHeap (Compare comparator, const allocator_type &allocator={}) noexcept(noexcept(container_type(allocator)) &&noexcept(Compare(std::move(comparator)))) |
| Constructs an empty heap with a specific allocator. | |
| constexpr | BinaryHeap (const BinaryHeap &)=default |
| constexpr | BinaryHeap (const BinaryHeap &rhs, const allocator_type &allocator) |
| constexpr | BinaryHeap (BinaryHeap &&)=default |
| constexpr | BinaryHeap (BinaryHeap &&rhs, const allocator_type &allocator) noexcept(noexcept(container_type(std::move(rhs.data_), allocator)) &&noexcept(Compare(std::move(rhs.comparator_)))) |
| template<std::input_iterator It> | |
| constexpr | BinaryHeap (It first, It last, Compare comparator={}, const allocator_type &allocator={}) |
| Iterator range constructor. | |
| constexpr | BinaryHeap (std::initializer_list< T > list, Compare comparator={}, const allocator_type &allocator={}) |
| Initializer list range constructor. | |
| ~BinaryHeap ()=default | |
| allocator_type | get_allocator () const noexcept |
| constexpr std::size_t | size () const noexcept |
| Return the heap size. | |
| constexpr std::size_t | capacity () const noexcept |
| Return the heap capacity. | |
| constexpr bool | empty () const noexcept |
| Return true if empty. | |
| const T & | top () const noexcept |
| Return the min element. | |
| void | clear () noexcept |
| Clear the heap. | |
| void | reserve (std::size_t capacity) |
| Reserve the heap capacity. | |
| void | push (const T &value) |
| Push the value to the heap. | |
| void | push (T &&value) |
| Push the value to the heap. | |
| template<typename ... Args> | |
| void | emplace (Args &&... args) |
| Construct the value inplace in the heap. | |
| void | drop () noexcept(std::is_nothrow_move_assignable_v< T >) |
| Drop the min element. | |
| T | pop () noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_assignable_v< T >) |
| Pop the min element. | |
Private Member Functions | |
| std::size_t | fixDownWithHole (std::size_t index) noexcept(std::is_nothrow_move_assignable_v< T >) |
| void | fixUp (std::size_t index, std::size_t top, T &&value) noexcept(std::is_nothrow_move_assignable_v< T >) |
| void | heapify () noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_assignable_v< T >) |
Static Private Member Functions | |
| static constexpr bool | hasParent (std::size_t i) noexcept |
| static constexpr std::size_t | getParent (std::size_t i) noexcept |
| static constexpr std::size_t | getLeftChild (std::size_t i) noexcept |
Private Attributes | |
| container_type | data_ |
| Compare | comparator_ |
A binary min-heap container. Supports custom comparator and allocator.
Definition at line 14 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::allocator_type = container_type::allocator_type |
Definition at line 25 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::const_iterator = const T* |
Definition at line 22 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::const_pointer = const T* |
Definition at line 20 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::const_reference = const T& |
Definition at line 18 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::container_type = Vector<T, Allocator> |
Definition at line 24 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::difference_type = std::ptrdiff_t |
Definition at line 23 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::iterator = T* |
Definition at line 21 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::pointer = T* |
Definition at line 19 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::reference = T& |
Definition at line 17 of file flow_binary_heap.h.
| using flow::BinaryHeap< T, Compare, Allocator >::value_type = T |
Definition at line 16 of file flow_binary_heap.h.
|
inlineconstexprnoexcept |
Constructs an empty heap with default comparator and allocator. Comparator must be default initializable.
Definition at line 34 of file flow_binary_heap.h.
References comparator_, and data_.
Referenced by BinaryHeap(), BinaryHeap(), BinaryHeap(), and BinaryHeap().
|
inlineexplicitconstexprnoexcept |
Constructs an empty heap with a specific allocator. Comparator must be default initializable.
Definition at line 42 of file flow_binary_heap.h.
References comparator_, and data_.
|
inlineexplicitconstexprnoexcept |
Constructs an empty heap with a specific allocator.
| comparator | Comparator. |
| allocator | Memory allocator. |
Definition at line 51 of file flow_binary_heap.h.
|
constexprdefault |
References BinaryHeap().
|
inlineconstexpr |
Definition at line 58 of file flow_binary_heap.h.
References BinaryHeap(), comparator_, and data_.
|
constexprdefault |
References BinaryHeap().
|
inlineconstexprnoexcept |
Definition at line 63 of file flow_binary_heap.h.
References BinaryHeap(), comparator_, and data_.
|
inlineexplicitconstexpr |
Iterator range constructor.
| first | Iterator to first element. |
| last | Iterator to one-past-last element. |
| comp | Comparator. |
| alloc | Allocator. |
Definition at line 74 of file flow_binary_heap.h.
|
inlineexplicitconstexpr |
Initializer list range constructor.
| list | Initializer list. |
| comp | Comparator. |
| alloc | Allocator. |
Definition at line 83 of file flow_binary_heap.h.
|
default |
|
inlineconstexprnoexcept |
Return the heap capacity.
Definition at line 104 of file flow_binary_heap.h.
References data_.
Referenced by reserve().
|
inlinenoexcept |
|
inlinenoexcept |
Drop the min element.
Definition at line 154 of file flow_binary_heap.h.
References data_, fixDownWithHole(), and fixUp().
Referenced by pop().
|
inline |
Construct the value inplace in the heap.
| ...args | Constructor arguments. |
Definition at line 147 of file flow_binary_heap.h.
|
inlineconstexprnoexcept |
Return true if empty.
Definition at line 110 of file flow_binary_heap.h.
References data_.
|
inlineprivatenoexcept |
Definition at line 175 of file flow_binary_heap.h.
References comparator_, data_, and getLeftChild().
Referenced by drop().
|
inlineprivatenoexcept |
Definition at line 195 of file flow_binary_heap.h.
References comparator_, data_, getParent(), and top().
|
inlinenoexcept |
Definition at line 90 of file flow_binary_heap.h.
References data_.
|
inlinestaticconstexprprivatenoexcept |
Definition at line 230 of file flow_binary_heap.h.
Referenced by fixDownWithHole().
|
inlinestaticconstexprprivatenoexcept |
|
inlinestaticconstexprprivatenoexcept |
Definition at line 221 of file flow_binary_heap.h.
|
inlineprivatenoexcept |
Definition at line 209 of file flow_binary_heap.h.
References data_.
|
inlinenoexcept |
Pop the min element.
Definition at line 164 of file flow_binary_heap.h.
|
inline |
Push the value to the heap.
| value |
Definition at line 134 of file flow_binary_heap.h.
References emplace().
|
inline |
|
inline |
Reserve the heap capacity.
| capacity |
Definition at line 128 of file flow_binary_heap.h.
References capacity(), and data_.
|
inlineconstexprnoexcept |
Return the heap size.
Definition at line 98 of file flow_binary_heap.h.
References data_.
|
inlinenoexcept |
|
private |
Definition at line 29 of file flow_binary_heap.h.
Referenced by BinaryHeap(), BinaryHeap(), BinaryHeap(), BinaryHeap(), fixDownWithHole(), and fixUp().
|
private |
Definition at line 28 of file flow_binary_heap.h.
Referenced by BinaryHeap(), BinaryHeap(), BinaryHeap(), BinaryHeap(), capacity(), clear(), drop(), emplace(), empty(), fixDownWithHole(), fixUp(), get_allocator(), heapify(), pop(), reserve(), size(), and top().