50# ifndef TPL_DYNBINHEAP_H
51# define TPL_DYNBINHEAP_H
54# include <type_traits>
77 template <
class T,
class Compare = Aleph::less<T>>
78 requires StrictWeakOrder<Compare, T>
103 std::unique_ptr<Node> node(p);
105 return node.release()->get_key();
124 DynBinHeap(Compare &
cmp)
noexcept(std::is_nothrow_constructible_v<Base, Compare &>)
129 noexcept(
std::is_nothrow_constructible_v<
Base, Compare &>)
209 return insert(std::forward<T>(item));
224 return std::move(node->get_key());
249 Node * node = Node::key_to_node(data);
305 template <
class Operation>
310 {
return op(p->get_key()); });
313 template <
class Operation>
320 template <
class Operation>
325 {
return op(
static_cast<const T &
>(p->get_key())); });
328 template <
class Operation>
332 return traverse<Operation>(op);
344 return KEY(Base::Iterator::get_curr_ne());
Variadic constructor macros for containers.
#define Args_Ctor(Name, Type)
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
Container traversal and functional operation mixins.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Dynamic heap of elements of type T ordered by a comparison functor.
bool traverse(Operation &op) const
T get()
Alias for getMin().
bool traverse(Operation &&op=Operation()) const
bool traverse(Operation &op)
T getMin()
Remove the minimum element (according to Compare) and return it.
DynBinHeap(const DynBinHeap &h)
void clear() noexcept
Removes all elements from the heap.
void copy(const DynBinHeap &src)
void empty() noexcept
Remove every element.
bool remove(T &data) noexcept(Base::nothrow_cmp)
Remove an arbitrary element belonging to the heap.
bool traverse(Operation &&op=Operation())
T & put(const T &item)
Synonym of insert().
T getMax()
See getMin(); to use if the order of priority is reversed.
typename BinHeap< T, Compare >::Node Node
void update(T &data) noexcept(Base::nothrow_cmp)
Adjust the position of an element after mutating its priority.
DynBinHeap(Compare &cmp) noexcept(std::is_nothrow_constructible_v< Base, Compare & >)
Builds an empty heap with the comparison cmp.
T & __insert(Node *p) noexcept(Base::nothrow_cmp)
DynBinHeap(DynBinHeap &&h)
DynBinHeap & operator=(const DynBinHeap &h)
bool erase(T &data) noexcept(Base::nothrow_cmp)
Alias for remove().
T & insert(const T &item)
Insert a copy of item into the heap.
const T & top() const
Return a reference to the smallest element.
DynBinHeap(Compare &&cmp=Compare()) noexcept(std::is_nothrow_constructible_v< Base, Compare & >)
See DynBinHeap(Compare & cmp).
T & append(const T &item)
bool preorder_traverse(Node *p, Operation op) const
Node * insert(Node *p) noexcept(nothrow_cmp)
Inserts a node into a heap.
bool is_empty() const noexcept
void update(Node *p) noexcept(nothrow_cmp)
Updates the priority of a node contained in the heap.
Node * remove(Node *node)
Removes node from the heap.
void remove_all_and_delete() noexcept
Deletes all the nodes of the heap, invokes the destructors of the removed nodes, and frees all the me...
void for_each_in_preorder(Operation &operation) const
Node * top()
Returns the node with the lowest priority according to the comparison criterion specified in the decl...
Node * getMin()
Removes the node with the lowest priority from the heap.
static constexpr bool nothrow_cmp
Common methods to the Aleph-w ( ) containers.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
f(args...) is a valid call whose result is usable as a condition.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
std::decay_t< typename HeadC::Item_Type > T
Node heap without virtual destructor.
const T & get_curr_ne() const noexcept
const T & get_curr() const
Iterator() noexcept=default
Default constructor creates an "end" iterator.
Generic list of items stored in a container.
Binary heap implementation using tree structure.
Utility functions for binary tree operations.