Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::DynBinHeap< T, Compare > Class Template Reference

Dynamic heap of elements of type T ordered by a comparison functor. More...

#include <tpl_dynBinHeap.H>

Inheritance diagram for Aleph::DynBinHeap< T, Compare >:
[legend]
Collaboration diagram for Aleph::DynBinHeap< T, Compare >:
[legend]

Classes

struct  Iterator
 

Public Types

using Set_Type = DynBinHeap
 
using Item_Type = T
 
using Key_Type = T
 
- Public Types inherited from Aleph::BinHeap< Key, Compare >
using Node = BinHeapNode< Key >
 The heap's node type.
 
- Public Types inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
using Node = NodeType< Key >
 
- Public Types inherited from StlAlephIterator< SetName >
using iterator = StlIterator< SetName >
 
using const_iterator = StlConstIterator< SetName >
 

Public Member Functions

 DynBinHeap (Compare &cmp) noexcept(std::is_nothrow_constructible_v< Base, Compare & >)
 Builds an empty heap with the comparison cmp.
 
 DynBinHeap (Compare &&cmp=Compare()) noexcept(std::is_nothrow_constructible_v< Base, Compare & >)
 See DynBinHeap(Compare & cmp).
 
 DynBinHeap (const DynBinHeap &h)
 
 DynBinHeap (DynBinHeap &&h)
 
template<template< typename > class List>
 DynBinHeap (const List< T > &l)
 
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
 DynBinHeap (It b, It e)
 
 DynBinHeap (std::initializer_list< T > l)
 
template<typename ... Args>
 DynBinHeap (const T &item, Args &... args)
 
template<typename ... Args>
 DynBinHeap (T &&item, Args &... args)
 
DynBinHeap & operator= (const DynBinHeap &h)
 
DynBinHeap & operator= (DynBinHeap &&h) noexcept
 
T & insert (const T &item)
 Insert a copy of item into the heap.
 
T & insert (T &&item)
 
T & append (const T &item)
 
T & append (T &&item)
 
T & put (const T &item)
 Synonym of insert().
 
T & put (T &&item)
 
T getMin ()
 Remove the minimum element (according to Compare) and return it.
 
T getMax ()
 See getMin(); to use if the order of priority is reversed.
 
T get ()
 Alias for getMin().
 
void update (T &data) noexcept(Base::nothrow_cmp)
 Adjust the position of an element after mutating its priority.
 
bool remove (T &data) noexcept(Base::nothrow_cmp)
 Remove an arbitrary element belonging to the heap.
 
bool erase (T &data) noexcept(Base::nothrow_cmp)
 Alias for remove().
 
const T & top () const
 Return a reference to the smallest element.
 
void empty () noexcept
 Remove every element.
 
void clear () noexcept
 Removes all elements from the heap.
 
 ~DynBinHeap ()
 Destructor.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool traverse (Operation &op)
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool traverse (Operation &&op=Operation())
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool traverse (Operation &op) const
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool traverse (Operation &&op=Operation()) const
 
- Public Member Functions inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
Compare & key_comp () noexcept
 
Compare & get_compare () noexcept
 
void swap (GenBinHeap &h) noexcept
 
Node * getRoot () noexcept
 
Node * getRoot () const noexcept
 
template<class Operation >
bool preorder_traverse (Operation op) const
 
template<class Operation >
void for_each_in_preorder (Operation &operation) const
 
template<class Operation >
void for_each_in_preorder (Operation &&operation=Operation()) const
 
template<class Operation >
void for_each_in_inorder (Operation &operation) const
 
template<class Operation >
void for_each_in_inorder (Operation &&operation=Operation()) const
 
template<class Op >
bool level_traverse (Op operation=Op()) const
 
 GenBinHeap () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_constructible_v< Compare, Compare & >)
 Builds an empty heap with a comparison built by default.
 
 GenBinHeap (Compare __cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >)
 Builds an empty heap with the comparison __cmp.
 
virtual ~GenBinHeap () noexcept
 
Node * insert (Node *p) noexcept(nothrow_cmp)
 Inserts a node into a heap.
 
Node * getMin_ne () noexcept(nothrow_cmp)
 Removes the node with the lowest priority from a heap that is not empty.
 
Node * getMin ()
 Removes the node with the lowest priority from the heap.
 
Node * getMax ()
 See getMin(); to use when the priority order is reversed.
 
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 memory.
 
Node * top ()
 Returns the node with the lowest priority according to the comparison criterion specified in the declaration.
 
Node * top () const
 
const size_t & size () const noexcept
 
bool is_empty () const noexcept
 
bool verify_heap () const
 Checks the order of the heap.
 
- Public Member Functions inherited from LocateFunctions< Container, Type >
auto get_it ()
 Return a properly initialized iterator positioned at the first item on the container.
 
auto get_it () const
 Read-only iterator positioned at the first item.
 
auto get_it (const size_t pos)
 Return a properly initialized iterator positioned at the pos item on the container.
 
auto get_it (const size_t pos) const
 Read-only iterator positioned at the pos item.
 
auto get_itor ()
 Alias of get_it().
 
auto get_itor () const
 See get_itor().
 
template<class C = Container>
requires Aleph::dry_detail::MutablyTraversable<C, Type>
Type & nth_ne (const size_t n) noexcept(Aleph::dry_detail::mutable_traversal_is_noexcept< C, Type >)
 Return the n‑th element without bounds checking.
 
const Type & nth_ne (const size_t n) const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< Container, Type >)
 Constant overload of nth_ne(size_t).
 
template<class C = Container>
requires Aleph::dry_detail::MutablyTraversable<C, Type>
Type & nth (const size_t n)
 Return the n-th item of the container.
 
const Type & nth (const size_t n) const
 Const overload of nth(size_t).
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, Type &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr (Operation &operation) noexcept(mutable_search_is_noexcept< Operation >())
 Find a pointer to an item in the container according to a searching criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
const Type * find_ptr (Operation &operation) const noexcept(const_search_is_noexcept< Operation >())
 Const overload of find_ptr(Operation&).
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
const Type * find_ptr (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >())
 Overload of find_ptr() const that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, Type &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr (Operation &&operation) noexcept(mutable_search_is_noexcept< Operation >())
 Overload of find_ptr() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
size_t find_index (Operation &operation) const noexcept(const_search_is_noexcept< Operation >())
 Find the position of an item in the container according to a searching criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
size_t find_index (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >())
 Overload of find_index() that accepts rvalues.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, Type > find_item (Operation &operation) const noexcept(find_item_is_noexcept< Operation >())
 Safe sequential searching of an item matching a criterion.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, Type > find_item (Operation &&operation) const noexcept(find_item_is_noexcept< Operation >())
 Overload of find_item() that accepts rvalues.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::copy_constructible< T > std::optional< Type > find_opt (Operation &operation) const
 Copy of the first item satisfying a criterion, if any.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::copy_constructible< T > std::optional< Type > find_opt (Operation &&operation) const
 Overload of find_opt() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
bool contains_if (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >())
 Test if an item satisfying a criterion is present in the container.
 
template<class T = Type>
requires requires(const T & a, const T & b) { { a == b } -> std::convertible_to<bool>; }
bool contains (const Type &item) const
 Test if an item is present in the container using equality.
 
- Public Member Functions inherited from FunctionalMethods< Container, T >
void emplace (Args &&... args)
 Appends a new element into the container by constructing it from the given args.
 
void emplace_end (Args &&... args)
 See emplace(Args && ... args).
 
void emplace_ins (Args &&... args)
 
template<typename... Args>
requires ((std::convertible_to<Args &&, T> and ...) and (Aleph::InsertableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<Args...>>::type, Item_Arg<Args>> and ...))
size_t ninsert (Args &&... args)
 Insert n variadic items.
 
template<typename... Args>
requires ((std::convertible_to<Args &&, T> and ...) and (Aleph::AppendableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<Args...>>::type, Item_Arg<Args>> and ...))
size_t nappend (Args &&... args)
 Append n variadic items.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void for_each (Operation &operation) const
 Traverse all the container and performs an operation on each element.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void for_each (Operation &&operation) const
 Overload of for_each() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (Operation &operation) const
 Alias of for_each().
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (Operation &&operation) const
 Alias of for_each() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (const size_t pos, const size_t slice, Operation &operation) const
 Traverse the container starting at pos taking one item every slice, performing an operation on each visited element.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (const size_t pos, const size_t slice, Operation &&operation) const
 See each(size_t pos, size_t slice, Operation & operation) const.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void each (const size_t pos, const size_t slice, Operation &operation)
 Traverse the container starting at pos taking one item every slice, performing an operation that may modify each visited item.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void each (const size_t pos, const size_t slice, Operation &&operation)
 See each(size_t pos, size_t slice, Operation & operation).
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void mutable_for_each (Operation &operation)
 Apply a mutable operation to each element of the container.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void mutable_for_each (Operation &&operation)
 See mutable_for_each(Operation & operation).
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool all (Operation &operation) const
 Check if all the elements of the container satisfy a condition.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool all (Operation &&operation) const
 Overload of all() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool exists (Operation &op) const
 Test for existence in the container of an element satisfying a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool exists (Operation &&op) const
 Overload of exists() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool none (Operation &op) const
 Test that no element satisfies a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool none (Operation &&op) const
 Overload of none() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
size_t count_if (Operation &op) const
 Count the elements that satisfy a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
size_t count_if (Operation &&op) const
 Overload of count_if() that accepts rvalues.
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps (Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps (Operation &&op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps_if (Prop prop, Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps_if (Prop prop, Operation &&op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map (Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map (Operation &&op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map_if (Prop prop, Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map_if (Prop prop, Operation &&op) const
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
auto flat_map (Operation &op) const
 Map each element to a container and concatenate the results.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
auto flat_map (Operation &&op) const
 Overload of flat_map() that accepts rvalues.
 
Aleph::DynList< T > to_dynlist () const
 Convert container to DynList.
 
std::vector< T > to_vector () const
 Convert container to std::vector.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc foldl (const Acc &init, Op &op) const
 Fold the elements of the container to a specific result.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc foldl (const Acc &init, Op &&op) const
 Overload of foldl() that accepts rvalues.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc fold_left (const Acc &init, Op &op) const
 Alias for foldl().
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc fold_left (const Acc &init, Op &&op) const
 Overload of fold_left() that accepts rvalues.
 
template<class Operation >
requires Aleph::dry_detail::FoldOperation<Operation, T, T>
T fold (const T &init, Operation &operation) const
 Simplified version of foldl() where the folded type is the same type of elements stored in the container.
 
template<class Operation >
requires Aleph::dry_detail::FoldOperation<Operation, T, T>
T fold (const T &init, Operation &&operation) const
 Overload of fold() that accepts rvalues.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldRightOperation<Op, Acc, T>
Acc foldr (const Acc &init, Op &op) const
 Fold the elements from the last to the first.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldRightOperation<Op, Acc, T>
Acc foldr (const Acc &init, Op &&op) const
 Overload of foldr() that accepts rvalues.
 
template<class Op , class U = T>
requires Aleph::dry_detail::FoldOperation<Op, T, T>
and std::copy_constructible< U > std::optional< T > reduce (Op &op) const
 Fold the elements with no initial value.
 
template<class Op , class U = T>
requires Aleph::dry_detail::FoldOperation<Op, T, T>
and std::copy_constructible< U > std::optional< T > reduce (Op &&op) const
 Overload of reduce() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > filter (Operation &operation) const
 Filter the elements of a container according to a matching criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > filter (Operation &&operation) const
 Overload of filter() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< const T * > ptr_filter (Operation &operation) const
 Filter the elements of a container according to a matching criterion and return a pointer to the matched items in the container.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< const T * > ptr_filter (Operation &&operation) const
 Overload of ptr_filter() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &operation) const
 Filter the elements of a container according to a matching criterion and determine its positions respect to the traversal of container.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &&operation) const
 Overload of pfilter() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &op) const
 Exclusive partition of container according to a filter criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &&op) const
 Overload of partition() that accepts rvalues.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (size_t n) const
 Exclusive partition of container in the nth item.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > split_half () const
 Split the container into two halves by alternating elements.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &op) const
 Exclusive partition of container according to a filter criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &&op) const
 Overload of tpartition() that accepts rvalues.
 
size_t length () const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< Container, T >)
 Count the number of elements of a container.
 
Aleph::DynList< T > rev () const
 Return a list with the elements of container in reverse order respect to its traversal order.
 
Aleph::DynList< T > take (const size_t n) const
 Return a list with the first n elements seen in the container during its traversal.
 
Aleph::DynList< T > take (size_t i, const size_t j, const size_t step=1) const
 Return a list with the elements at positions i, i + step, i + 2 step, ... that are not greater than j, respect to the traversal order.
 
Aleph::DynList< T > drop (const size_t n) const
 Drop the first n elements seen in the container during its traversal.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > take_while (Operation &op) const
 The longest prefix of elements that satisfy a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > take_while (Operation &&op) const
 Overload of take_while() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > drop_while (Operation &op) const
 The elements after the longest prefix that satisfies a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > drop_while (Operation &&op) const
 Overload of drop_while() that accepts rvalues.
 
template<class C = Container>
requires requires (C & c) { c.remove(); }
void mutable_drop (const size_t n)
 Drop the first n elements seen from container.
 
- Public Member Functions inherited from GenericItems< Container, T >
Aleph::DynList< T > items () const
 Return a list of all the elements of a container sorted by traversal order.
 
Aleph::DynList< T > keys () const
 See items().
 
- Public Member Functions inherited from StlAlephIterator< SetName >
iterator begin () noexcept
 Return an STL-compatible iterator to the first element.
 
iterator end () noexcept
 Return an STL-compatible end iterator.
 
const_iterator begin () const noexcept
 Return a const iterator to the first element.
 
const_iterator end () const noexcept
 Return a const end iterator.
 
const_iterator cbegin () const noexcept
 Return a const iterator to the first element.
 
const_iterator cend () const noexcept
 Return a const end iterator.
 

Private Types

using Base = BinHeap< T, Compare >
 
using Node = typename BinHeap< T, Compare >::Node
 

Private Member Functions

T & __insert (Node *p) noexcept(Base::nothrow_cmp)
 
void copy (const DynBinHeap &src)
 

Additional Inherited Members

- Static Public Member Functions inherited from FunctionalMethods< Container, T >
template<typename... Items>
requires ((std::convertible_to<Items &&, T> and ...) and (Aleph::AppendableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<Items...>>::type, Item_Arg<Items>> and ...))
static Container build (Items &&... items)
 Build a container that holds the given items.
 
template<class D , typename... Items>
requires (std::derived_from<D, typename Aleph::concepts_detail::defer<Container, D>::type> and std::default_initializable<D> and (std::convertible_to<Items &&, T> and ...) and (Aleph::AppendableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<D, Items...>>::type, Item_Arg<Items>> and ...))
static D build_as (Items &&... items)
 Build a D, a class derived from the container, holding the given items.
 
- Public Attributes inherited from FunctionalMethods< Container, T >
template<typename... Args>
requires (typename Aleph::concepts_detail::defer<Container, std::tuple<Args...>>::type & c, T && x)
 and { c.append(std::move(x))
 Insert a new element into the container by constructing it from the given args.
 
template<typename R = void, class Prop , class Operation >
requires (Aleph::DynList<Aleph::dry_detail::map_result_t<R, Operation &, T>> & l, Operation & op, const T & item)
and Aleph::InvocableWith< Operation &, const T & > and { l.append(std::invoke(op, item))
 Conditional mapping of the elements of the container.
 
- Protected Member Functions inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
virtual bool verify_heap (Node *p) const
 Whether no node of the tree of root p has a key less than that of its parent.
 
- Static Protected Member Functions inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
static Node * advance_left (Node *p) noexcept
 The left child of p, or null if it has none.
 
static Node * advance_right (Node *p) noexcept
 The right child of p, or null if it has none.
 
- Protected Attributes inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
Compare cmp
 
- Static Protected Attributes inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
static constexpr bool nothrow_cmp
 

Detailed Description

template<class T, class Compare = Aleph::less<T>>
requires StrictWeakOrder<Compare, T>
class Aleph::DynBinHeap< T, Compare >

Dynamic heap of elements of type T ordered by a comparison functor.

DynBinHeap stores items in a binary heap whose nodes are allocated dynamically (no backing array), so the structure can grow or shrink as needed.

Author
Leandro Rabindranath León

Definition at line 79 of file tpl_dynBinHeap.H.

Member Typedef Documentation

◆ Base

template<class T , class Compare = Aleph::less<T>>
using Aleph::DynBinHeap< T, Compare >::Base = BinHeap<T, Compare>
private

Definition at line 95 of file tpl_dynBinHeap.H.

◆ Item_Type

template<class T , class Compare = Aleph::less<T>>
using Aleph::DynBinHeap< T, Compare >::Item_Type = T

Definition at line 89 of file tpl_dynBinHeap.H.

◆ Key_Type

template<class T , class Compare = Aleph::less<T>>
using Aleph::DynBinHeap< T, Compare >::Key_Type = T

Definition at line 91 of file tpl_dynBinHeap.H.

◆ Node

template<class T , class Compare = Aleph::less<T>>
using Aleph::DynBinHeap< T, Compare >::Node = typename BinHeap<T, Compare>::Node
private

Definition at line 97 of file tpl_dynBinHeap.H.

◆ Set_Type

template<class T , class Compare = Aleph::less<T>>
using Aleph::DynBinHeap< T, Compare >::Set_Type = DynBinHeap

Definition at line 87 of file tpl_dynBinHeap.H.

Constructor & Destructor Documentation

◆ DynBinHeap() [1/9]

template<class T , class Compare = Aleph::less<T>>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( Compare &  cmp)
inlinenoexcept

Builds an empty heap with the comparison cmp.

Parameters
[in]cmpthe criterion of comparison, which the heap copies.
Exceptions
whatthe default construction of the key of the header node or the copy of cmp throws; nothing when both are noexcept.

Definition at line 124 of file tpl_dynBinHeap.H.

◆ DynBinHeap() [2/9]

template<class T , class Compare = Aleph::less<T>>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( Compare &&  cmp = Compare())
inlinenoexcept

See DynBinHeap(Compare & cmp).

Definition at line 128 of file tpl_dynBinHeap.H.

◆ DynBinHeap() [3/9]

template<class T , class Compare = Aleph::less<T>>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( const DynBinHeap< T, Compare > &  h)
inline

◆ DynBinHeap() [4/9]

template<class T , class Compare = Aleph::less<T>>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( DynBinHeap< T, Compare > &&  h)
inline

Definition at line 146 of file tpl_dynBinHeap.H.

References h, and Aleph::swap().

◆ DynBinHeap() [5/9]

template<class T , class Compare = Aleph::less<T>>
template<template< typename > class List>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( const List< T > &  l)
inline

Definition at line 151 of file tpl_dynBinHeap.H.

◆ DynBinHeap() [6/9]

template<class T , class Compare = Aleph::less<T>>
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( It  b,
It  e 
)
inline

Definition at line 151 of file tpl_dynBinHeap.H.

◆ DynBinHeap() [7/9]

template<class T , class Compare = Aleph::less<T>>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( std::initializer_list< T >  l)
inline

Definition at line 151 of file tpl_dynBinHeap.H.

◆ DynBinHeap() [8/9]

template<class T , class Compare = Aleph::less<T>>
template<typename ... Args>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( const T &  item,
Args &...  args 
)
inline

Definition at line 153 of file tpl_dynBinHeap.H.

◆ DynBinHeap() [9/9]

template<class T , class Compare = Aleph::less<T>>
template<typename ... Args>
Aleph::DynBinHeap< T, Compare >::DynBinHeap ( T &&  item,
Args &...  args 
)
inline

Definition at line 153 of file tpl_dynBinHeap.H.

◆ ~DynBinHeap()

template<class T , class Compare = Aleph::less<T>>
Aleph::DynBinHeap< T, Compare >::~DynBinHeap ( )
inline

Destructor.

Definition at line 300 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::empty().

Member Function Documentation

◆ __insert()

◆ append() [1/2]

template<class T , class Compare = Aleph::less<T>>
T & Aleph::DynBinHeap< T, Compare >::append ( const T &  item)
inline

Definition at line 191 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::__insert().

◆ append() [2/2]

template<class T , class Compare = Aleph::less<T>>
T & Aleph::DynBinHeap< T, Compare >::append ( T &&  item)
inline

Definition at line 196 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::__insert().

◆ clear()

template<class T , class Compare = Aleph::less<T>>
void Aleph::DynBinHeap< T, Compare >::clear ( )
inlinenoexcept

Removes all elements from the heap.

Exceptions
none
Note
This method delegates to empty() and is noexcept.

Definition at line 297 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::empty().

◆ copy()

template<class T , class Compare = Aleph::less<T>>
void Aleph::DynBinHeap< T, Compare >::copy ( const DynBinHeap< T, Compare > &  src)
inlineprivate

◆ empty()

◆ erase()

template<class T , class Compare = Aleph::less<T>>
bool Aleph::DynBinHeap< T, Compare >::erase ( T &  data)
inlinenoexcept

Alias for remove().

Definition at line 274 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::remove().

◆ get()

◆ getMax()

template<class T , class Compare = Aleph::less<T>>
T Aleph::DynBinHeap< T, Compare >::getMax ( )
inline

See getMin(); to use if the order of priority is reversed.

Definition at line 228 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::getMin().

◆ getMin()

template<class T , class Compare = Aleph::less<T>>
T Aleph::DynBinHeap< T, Compare >::getMin ( )
inline

Remove the minimum element (according to Compare) and return it.

Returns
the removed element.
Exceptions
underflow_errorif the heap is empty.
anythingthat the comparison throws. Then the element is in the heap, which is as it was.

Definition at line 219 of file tpl_dynBinHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::getMin().

Referenced by Aleph::DynBinHeap< T, Compare >::get(), Aleph::DynBinHeap< T, Compare >::getMax(), main(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::pop_best_pair(), Aleph::ssp_shortest_path(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ insert() [1/2]

template<class T , class Compare = Aleph::less<T>>
T & Aleph::DynBinHeap< T, Compare >::insert ( const T &  item)
inline

Insert a copy of item into the heap.

Parameters
[in]itemvalue to insert.
Returns
reference to the stored element.
Exceptions
bad_allocif allocation fails.
anythingthat the comparison throws. Then the item is not in the heap, which is as it was.

Definition at line 181 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::__insert().

Referenced by demo_binary_heap(), demo_event_simulation(), demo_max_heap(), demo_performance_comparison(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::enqueue_pair_if_needed(), main(), Aleph::DynBinHeap< T, Compare >::put(), Aleph::DynBinHeap< T, Compare >::put(), Aleph::ssp_shortest_path(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ insert() [2/2]

template<class T , class Compare = Aleph::less<T>>
T & Aleph::DynBinHeap< T, Compare >::insert ( T &&  item)
inline

Definition at line 186 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::__insert().

◆ operator=() [1/2]

template<class T , class Compare = Aleph::less<T>>
DynBinHeap & Aleph::DynBinHeap< T, Compare >::operator= ( const DynBinHeap< T, Compare > &  h)
inline

◆ operator=() [2/2]

template<class T , class Compare = Aleph::less<T>>
DynBinHeap & Aleph::DynBinHeap< T, Compare >::operator= ( DynBinHeap< T, Compare > &&  h)
inlinenoexcept

Definition at line 167 of file tpl_dynBinHeap.H.

References h, and Aleph::swap().

◆ put() [1/2]

◆ put() [2/2]

template<class T , class Compare = Aleph::less<T>>
T & Aleph::DynBinHeap< T, Compare >::put ( T &&  item)
inline

Definition at line 207 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::insert().

◆ remove()

template<class T , class Compare = Aleph::less<T>>
bool Aleph::DynBinHeap< T, Compare >::remove ( T &  data)
inlinenoexcept

Remove an arbitrary element belonging to the heap.

The reference must have been obtained from insert(). The underlying node is freed.

Parameters
dataelement to erase.
Returns
true if a node was removed.
Exceptions
anythingthat the comparison throws. Then the element is in the heap, which is as it was.

Definition at line 263 of file tpl_dynBinHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::is_empty(), and Aleph::GenBinHeap< NodeType, Key, Compare >::remove().

Referenced by Aleph::DynBinHeap< T, Compare >::erase(), and TEST().

◆ top()

template<class T , class Compare = Aleph::less<T>>
const T & Aleph::DynBinHeap< T, Compare >::top ( ) const
inline

Return a reference to the smallest element.

Definition at line 280 of file tpl_dynBinHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::top().

Referenced by demo_binary_heap(), demo_max_heap(), TEST(), TEST(), TEST(), and TEST().

◆ traverse() [1/4]

template<class T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool Aleph::DynBinHeap< T, Compare >::traverse ( Operation &&  op = Operation())
inline

Definition at line 315 of file tpl_dynBinHeap.H.

References Aleph::DynBinHeap< T, Compare >::traverse().

◆ traverse() [2/4]

template<class T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool Aleph::DynBinHeap< T, Compare >::traverse ( Operation &&  op = Operation()) const
inline

Definition at line 330 of file tpl_dynBinHeap.H.

◆ traverse() [3/4]

template<class T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool Aleph::DynBinHeap< T, Compare >::traverse ( Operation &  op)
inline

◆ traverse() [4/4]

template<class T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool Aleph::DynBinHeap< T, Compare >::traverse ( Operation &  op) const
inline

◆ update()

template<class T , class Compare = Aleph::less<T>>
void Aleph::DynBinHeap< T, Compare >::update ( T &  data)
inlinenoexcept

Adjust the position of an element after mutating its priority.

Parameters
[in]datareference previously returned by insert().
Exceptions
anythingthat the comparison throws. Then no element has moved: the heap is as it was before the call, with data at its place, where its new priority may be out of order.
Note
Behavior is undefined if data does not belong to this heap.

Definition at line 247 of file tpl_dynBinHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::update().

Referenced by TEST(), and TEST().


The documentation for this class was generated from the following file: