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 | allocator_type = std::allocator_traits<Allocator>::template rebind_alloc<T> |
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, const allocator_type &allocator={}) |
Iterator range constructor. Comparator must be default initializable. | |
template<std::input_iterator It> | |
constexpr | BinaryHeap (It first, It last, Compare comparator, const allocator_type &allocator={}) |
Iterator 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 Types | |
using | container_type = Vector<T, Allocator> |
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 = std::allocator_traits<Allocator>::template rebind_alloc<T> |
Definition at line 24 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.
|
private |
Definition at line 27 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_.
|
inlineconstexpr |
Iterator range constructor. Comparator must be default initializable.
first | Iterator to first element. |
last | Iterator to one-past-last element. |
alloc | Allocator. |
Definition at line 74 of file flow_binary_heap.h.
|
inlineconstexpr |
Iterator range constructor.
first | Iterator to first element. |
last | Iterator to one-past-last element. |
comp | Comparator. |
alloc | Allocator. |
Definition at line 85 of file flow_binary_heap.h.
|
default |
|
inlineconstexprnoexcept |
Return the heap capacity.
Definition at line 107 of file flow_binary_heap.h.
References data_.
Referenced by reserve().
|
inlinenoexcept |
|
inlinenoexcept |
Drop the min element.
Definition at line 157 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 150 of file flow_binary_heap.h.
|
inlineconstexprnoexcept |
Return true if empty.
Definition at line 113 of file flow_binary_heap.h.
References data_.
|
inlineprivatenoexcept |
Definition at line 178 of file flow_binary_heap.h.
References comparator_, data_, and getLeftChild().
Referenced by drop().
|
inlineprivatenoexcept |
Definition at line 198 of file flow_binary_heap.h.
References comparator_, data_, getParent(), and top().
|
inlinenoexcept |
Definition at line 93 of file flow_binary_heap.h.
References data_.
|
inlinestaticconstexprprivatenoexcept |
Definition at line 233 of file flow_binary_heap.h.
Referenced by fixDownWithHole().
|
inlinestaticconstexprprivatenoexcept |
|
inlinestaticconstexprprivatenoexcept |
Definition at line 224 of file flow_binary_heap.h.
|
inlineprivatenoexcept |
Definition at line 212 of file flow_binary_heap.h.
References data_.
|
inlinenoexcept |
Pop the min element.
Definition at line 167 of file flow_binary_heap.h.
|
inline |
Push the value to the heap.
value |
Definition at line 137 of file flow_binary_heap.h.
References emplace().
|
inline |
|
inline |
Reserve the heap capacity.
capacity |
Definition at line 131 of file flow_binary_heap.h.
References capacity(), and data_.
|
inlineconstexprnoexcept |
Return the heap size.
Definition at line 101 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().