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

Fixed-capacity binary heap backed by a raw array. More...

#include <tpl_arrayHeap.H>

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

Classes

struct  Iterator
 

Public Types

using Item_Type = T
 
using Key_Type = T
 
using Const_Iterator = Aleph::Const_Iterator< Iterator >
 Read-only iterator: the iterator of a constant container.
 
- Public Types inherited from StlAlephIterator< SetName >
using iterator = StlIterator< SetName >
 
using const_iterator = StlConstIterator< SetName >
 

Public Member Functions

void allocate_storage (const size_t new_dim)
 Allocate internal storage and reset the heap.
 
void swap (ArrayHeap &h) noexcept
 Swap all state with another heap.
 
template<template< typename > class List>
 ArrayHeap (const List< T > &l)
 
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
 ArrayHeap (It b, It e)
 
 ArrayHeap (std::initializer_list< T > l)
 
 ArrayHeap (const size_t d=1024, Compare cmp_fct=Compare())
 Construct an empty heap with internal storage.
 
 ArrayHeap (T *ptr, const size_t &d, Compare cmp_fct=Compare())
 Construct an empty heap using an external buffer.
 
 ArrayHeap (const ArrayHeap &h)
 
 ArrayHeap (ArrayHeap &&h) noexcept
 
ArrayHeap & operator= (const ArrayHeap &h)
 
ArrayHeap & operator= (ArrayHeap &&h) noexcept
 
virtual ~ArrayHeap ()
 Destructor.
 
T & top ()
 Return a mutable reference to the minimum element.
 
const T & top () const
 Return a const reference to the minimum element.
 
T & insert_ne (const T &key)
 Insert an element without checking capacity.
 
T & insert_ne (T &&key)
 Insert an element without checking capacity (move overload).
 
T & insert (const T &key)
 Insert an element into the heap.
 
T & insert (T &&key)
 Insert an element into the heap (move overload).
 
T & put (const T &key)
 Synonym for insert().
 
T & append (const T &key)
 Synonym for insert().
 
T & put (T &&key)
 Synonym for insert() (move overload).
 
T & append (T &&key)
 Synonym for insert() (move overload).
 
T getMin ()
 Remove the smallest element in the heap and return a copy of its value.
 
T get ()
 See getMin().
 
T getMax ()
 See getMin().
 
constexpr size_t size () const noexcept
 Return the number of elements currently stored.
 
constexpr bool is_empty () const noexcept
 Return true if the heap is empty.
 
constexpr size_t capacity () const noexcept
 Return the maximum number of elements that can be stored.
 
void update (T &data)
 Update the priority of an element stored in the heap.
 
void remove (T &item)
 Remove an element from the heap given a reference to it.
 
T & operator[] (const size_t i)
 Return a mutable reference to the i-th entry (1-based).
 
const T & operator[] (const size_t i) const
 Const overload of operator[] (1-based).
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool traverse (Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
 Traverse all elements (const overload).
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool traverse (Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
 Traverse all elements.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool traverse (Operation &&operation=Operation()) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
 Traverse all elements (const forwarding overload).
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool traverse (Operation &&operation=Operation()) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
 Traverse all elements (forwarding overload).
 
- 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 Member Functions

template<class Operation >
bool traverse_impl (Operation &operation)
 
template<class Operation >
bool const_traverse_impl (Operation &operation) const
 

Static Private Member Functions

static size_t r_index (const size_t &i)
 

Private Attributes

T * array = nullptr
 
size_t dim = 0
 
size_t num_items = 0
 
bool array_allocated = false
 
Compare cmp
 

Static Private Attributes

static constexpr bool nothrow_cmp
 

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.
 

Detailed Description

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

Fixed-capacity binary heap backed by a raw array.

The heap stores elements from index 1 to num_items and keeps index 0 as sentinel, which simplifies the parent/child arithmetic.

What an exception leaves
Each operation says what it leaves when the comparison throws: the heap as it was, if the exchange of two items does not throw. When an operation of an item throws, its copy, its move or its exchange with another item, the guarantee is the basic one, as in the containers of the standard library: the heap has the count that it had or the one that the operation was giving it, which is that of the other heap in a copy assignment and one item fewer in remove(), and each of its entries holds an item in the state in which that operation left it. An item may then be lost or moved from, and the items may be out of order, so that the heap no longer gives its least item first: it may be destroyed or assigned to. A heap of items whose move and exchange do not throw, as nearly all are, comes to that only in its copy assignment, when the copy of an item throws.
Template Parameters
Telement type
Comparecomparator defining the priority order
See also
DynArrayHeap BinHeap DynBinHeap

Definition at line 441 of file tpl_arrayHeap.H.

Member Typedef Documentation

◆ Const_Iterator

template<typename T , class Compare = Aleph::less<T>>
using Aleph::ArrayHeap< T, Compare >::Const_Iterator = Aleph::Const_Iterator<Iterator>

Read-only iterator: the iterator of a constant container.

Definition at line 925 of file tpl_arrayHeap.H.

◆ Item_Type

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

Definition at line 510 of file tpl_arrayHeap.H.

◆ Key_Type

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

Definition at line 512 of file tpl_arrayHeap.H.

Constructor & Destructor Documentation

◆ ArrayHeap() [1/7]

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

Definition at line 514 of file tpl_arrayHeap.H.

◆ ArrayHeap() [2/7]

template<typename 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::ArrayHeap< T, Compare >::ArrayHeap ( It  b,
It  e 
)
inline

Definition at line 514 of file tpl_arrayHeap.H.

◆ ArrayHeap() [3/7]

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

Definition at line 514 of file tpl_arrayHeap.H.

◆ ArrayHeap() [4/7]

template<typename T , class Compare = Aleph::less<T>>
Aleph::ArrayHeap< T, Compare >::ArrayHeap ( const size_t  d = 1024,
Compare  cmp_fct = Compare() 
)
inline

Construct an empty heap with internal storage.

Parameters
[in]dcapacity (number of usable heap slots)
[in]cmp_fctcomparator
Exceptions
invalid_argumentif d == 0
overflow_errorif the array of d + 1 entries, with the entry 0 that a heap does not use, does not fit in a size_t
bad_allocif there is no memory for the array

Definition at line 525 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::allocate_storage().

◆ ArrayHeap() [5/7]

template<typename T , class Compare = Aleph::less<T>>
Aleph::ArrayHeap< T, Compare >::ArrayHeap ( T *  ptr,
const size_t &  d,
Compare  cmp_fct = Compare() 
)
inline

Construct an empty heap using an external buffer.

The heap will not manage the lifetime of ptr.

Parameters
[in]ptrexternal buffer (must have at least d + 1 elements)
[in]dcapacity (number of usable heap slots)
[in]cmp_fctcomparator
Exceptions
invalid_argumentif ptr == nullptr or d == 0

Definition at line 540 of file tpl_arrayHeap.H.

References ah_invalid_argument_if.

◆ ArrayHeap() [6/7]

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

◆ ArrayHeap() [7/7]

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

Definition at line 555 of file tpl_arrayHeap.H.

References h, and Aleph::ArrayHeap< T, Compare >::swap().

◆ ~ArrayHeap()

template<typename T , class Compare = Aleph::less<T>>
virtual Aleph::ArrayHeap< T, Compare >::~ArrayHeap ( )
inlinevirtual

Member Function Documentation

◆ allocate_storage()

template<typename T , class Compare = Aleph::less<T>>
void Aleph::ArrayHeap< T, Compare >::allocate_storage ( const size_t  new_dim)
inline

Allocate internal storage and reset the heap.

Parameters
[in]new_dimnew capacity (number of usable heap slots)
Exceptions
invalid_argumentif new_dim == 0
overflow_errorif the array of new_dim + 1 entries, with the entry 0 that a heap does not use, does not fit in a size_t. Then the heap is as it was.
bad_allocif there is no memory for the array; the heap is then as it was.

Definition at line 478 of file tpl_arrayHeap.H.

References ah_invalid_argument_if, ah_overflow_error_if, Aleph::ArrayHeap< T, Compare >::array, Aleph::ArrayHeap< T, Compare >::array_allocated, Aleph::ArrayHeap< T, Compare >::dim, and Aleph::ArrayHeap< T, Compare >::num_items.

Referenced by Aleph::ArrayHeap< T, Compare >::ArrayHeap(), Aleph::ArrayHeap< T, Compare >::ArrayHeap(), and Aleph::ArrayHeap< T, Compare >::operator=().

◆ append() [1/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::append ( const T &  key)
inline

Synonym for insert().

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
See also
insert()

Definition at line 708 of file tpl_arrayHeap.H.

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

◆ append() [2/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::append ( T &&  key)
inline

Synonym for insert() (move overload).

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
See also
insert(T &&)

Definition at line 724 of file tpl_arrayHeap.H.

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

◆ capacity()

template<typename T , class Compare = Aleph::less<T>>
constexpr size_t Aleph::ArrayHeap< T, Compare >::capacity ( ) const
inlineconstexprnoexcept

Return the maximum number of elements that can be stored.

This excludes the sentinel slot at index 0.

Definition at line 787 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::dim.

◆ const_traverse_impl()

template<typename T , class Compare = Aleph::less<T>>
template<class Operation >
bool Aleph::ArrayHeap< T, Compare >::const_traverse_impl ( Operation &  operation) const
inlineprivate

◆ get()

template<typename T , class Compare = Aleph::less<T>>
T Aleph::ArrayHeap< T, Compare >::get ( )
inline

See getMin().

Definition at line 766 of file tpl_arrayHeap.H.

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

Referenced by TEST().

◆ getMax()

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

See getMin().

Definition at line 772 of file tpl_arrayHeap.H.

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

Referenced by TEST().

◆ getMin()

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

Remove the smallest element in the heap and return a copy of its value.

getMin() extracts the element with the lowest value according to the configured comparator.

Exceptions
underflow_errorif the heap is empty.
whatthe comparison throws, with the heap as it was if the move of the items and the exchange of two of them do not throw.
Returns
the removed value.

Definition at line 737 of file tpl_arrayHeap.H.

References ah_underflow_error_if, Aleph::ArrayHeap< T, Compare >::array, Aleph::ArrayHeap< T, Compare >::cmp, Aleph::ArrayHeap< T, Compare >::num_items, and Aleph::sift_down().

Referenced by Aleph::ArrayHeap< T, Compare >::get(), Aleph::ArrayHeap< T, Compare >::getMax(), main(), TEST(), TEST(), TEST(), and TEST().

◆ insert() [1/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::insert ( const T &  key)
inline

Insert an element into the heap.

insert(key) stores a copy of key inside the heap.

Parameters
[in]keyvalue to insert.
Returns
a mutable reference to the inserted element.
Exceptions
overflow_errorif the internal array is full.

Definition at line 675 of file tpl_arrayHeap.H.

References ah_overflow_error_if, Aleph::ArrayHeap< T, Compare >::dim, Aleph::ArrayHeap< T, Compare >::insert_ne(), and Aleph::ArrayHeap< T, Compare >::num_items.

Referenced by Aleph::ArrayHeap< T, Compare >::append(), Aleph::ArrayHeap< T, Compare >::append(), main(), Aleph::ArrayHeap< T, Compare >::put(), Aleph::ArrayHeap< T, Compare >::put(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ insert() [2/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::insert ( T &&  key)
inline

Insert an element into the heap (move overload).

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
Exceptions
overflow_errorif the internal array is full
See also
insert(const T &)

Definition at line 688 of file tpl_arrayHeap.H.

References ah_overflow_error_if, Aleph::ArrayHeap< T, Compare >::dim, Aleph::ArrayHeap< T, Compare >::insert_ne(), and Aleph::ArrayHeap< T, Compare >::num_items.

◆ insert_ne() [1/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::insert_ne ( const T &  key)
inline

Insert an element without checking capacity.

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
Exceptions
whatthe comparison or the copy of key throw, with the heap as it was if the exchange of two items does not throw.
Warning
This method does not check for overflow.
See also
insert()

Definition at line 622 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::array, Aleph::ArrayHeap< T, Compare >::cmp, Aleph::ArrayHeap< T, Compare >::num_items, r, and Aleph::sift_up().

Referenced by Aleph::ArrayHeap< T, Compare >::insert(), Aleph::ArrayHeap< T, Compare >::insert(), and TEST().

◆ insert_ne() [2/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::insert_ne ( T &&  key)
inline

Insert an element without checking capacity (move overload).

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
Exceptions
whatthe comparison throws, with the heap as it was if the exchange of two items does not throw, and key too, which takes its item back by a move assignment. If that assignment throws too, what it throws goes out instead, and the item of key is lost.
Note
key may be an item of this heap. The move, which comes before the comparisons, changes that item where it is, and the heap does not put that item in order again.
Warning
This method does not check for overflow.
See also
insert()

Definition at line 649 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::array, Aleph::ArrayHeap< T, Compare >::cmp, Aleph::ArrayHeap< T, Compare >::num_items, r, and Aleph::sift_up().

◆ is_empty()

template<typename T , class Compare = Aleph::less<T>>
constexpr bool Aleph::ArrayHeap< T, Compare >::is_empty ( ) const
inlineconstexprnoexcept

Return true if the heap is empty.

Definition at line 781 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::num_items.

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

◆ operator=() [1/2]

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

Definition at line 577 of file tpl_arrayHeap.H.

References h, and Aleph::ArrayHeap< T, Compare >::swap().

◆ operator=() [2/2]

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

◆ operator[]() [1/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::operator[] ( const size_t  i)
inline

Return a mutable reference to the i-th entry (1-based).

No bounds checking is performed.

Parameters
[in]iindex
Returns
mutable reference to entry i

Definition at line 892 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::array.

◆ operator[]() [2/2]

template<typename T , class Compare = Aleph::less<T>>
const T & Aleph::ArrayHeap< T, Compare >::operator[] ( const size_t  i) const
inline

Const overload of operator[] (1-based).

Parameters
[in]iindex
Returns
const reference to entry i

Definition at line 902 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::array.

◆ put() [1/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::put ( const T &  key)
inline

Synonym for insert().

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
See also
insert()

Definition at line 700 of file tpl_arrayHeap.H.

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

◆ put() [2/2]

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::ArrayHeap< T, Compare >::put ( T &&  key)
inline

Synonym for insert() (move overload).

Parameters
[in]keyvalue to insert
Returns
a mutable reference to the inserted element
See also
insert(T &&)

Definition at line 716 of file tpl_arrayHeap.H.

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

◆ r_index()

template<typename T , class Compare = Aleph::less<T>>
static size_t Aleph::ArrayHeap< T, Compare >::r_index ( const size_t &  i)
inlinestaticprivate

Definition at line 462 of file tpl_arrayHeap.H.

◆ remove()

template<typename T , class Compare = Aleph::less<T>>
void Aleph::ArrayHeap< T, Compare >::remove ( T &  item)
inline

Remove an element from the heap given a reference to it.

The reference must refer to an element stored in this heap.

Parameters
[in,out]itemreference to the element to remove
Exceptions
underflow_errorif the heap is empty
whatthe comparison throws, with the heap as it was if the exchange of two items does not throw.
Note
It is essential that item is a valid reference into this heap.
The items need no default constructor.
The last item of the array is removed where it is: it stays in its entry, with what it holds, until another item takes the entry or the array is destroyed. With a comparison that may throw, so does any other item that is removed, unless it can be emptied with no throw: by a default constructor and a move assignment that do not throw or, failing that, by a move constructor that does not.

Definition at line 834 of file tpl_arrayHeap.H.

References ah_underflow_error_if, FunctionalMethods< Container, T >::and, Aleph::ArrayHeap< T, Compare >::array, Aleph::ArrayHeap< T, Compare >::cmp, Aleph::ArrayHeap< T, Compare >::nothrow_cmp, Aleph::ArrayHeap< T, Compare >::num_items, and Aleph::sift_down_up().

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

◆ size()

template<typename T , class Compare = Aleph::less<T>>
constexpr size_t Aleph::ArrayHeap< T, Compare >::size ( ) const
inlineconstexprnoexcept

Return the number of elements currently stored.

Definition at line 778 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::num_items.

Referenced by exists_in_heap(), main(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ swap()

template<typename T , class Compare = Aleph::less<T>>
void Aleph::ArrayHeap< T, Compare >::swap ( ArrayHeap< T, Compare > &  h)
inlinenoexcept

◆ top() [1/2]

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

Return a mutable reference to the minimum element.

Exceptions
underflow_errorif the heap is empty

Definition at line 595 of file tpl_arrayHeap.H.

References ah_underflow_error_if, Aleph::ArrayHeap< T, Compare >::array, and Aleph::ArrayHeap< T, Compare >::num_items.

Referenced by main(), TEST(), TEST(), and TEST().

◆ top() [2/2]

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

Return a const reference to the minimum element.

Exceptions
underflow_errorif the heap is empty

Definition at line 606 of file tpl_arrayHeap.H.

References ah_underflow_error_if, Aleph::ArrayHeap< T, Compare >::array, and Aleph::ArrayHeap< T, Compare >::num_items.

◆ traverse() [1/4]

template<typename T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool Aleph::ArrayHeap< T, Compare >::traverse ( Operation &&  operation = Operation()) const
inlinenoexcept

Traverse all elements (const forwarding overload).

Template Parameters
Operationcallable type
Parameters
[in]operationfunctor to apply
Returns
false if traversal was stopped early, true otherwise

Definition at line 990 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::const_traverse_impl().

◆ traverse() [2/4]

template<typename T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool Aleph::ArrayHeap< T, Compare >::traverse ( Operation &&  operation = Operation())
inlinenoexcept

Traverse all elements (forwarding overload).

Template Parameters
Operationcallable type
Parameters
[in]operationfunctor to apply
Returns
false if traversal was stopped early, true otherwise

Definition at line 1004 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::traverse_impl().

◆ traverse() [3/4]

template<typename T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool Aleph::ArrayHeap< T, Compare >::traverse ( Operation &  operation) const
inlinenoexcept

Traverse all elements (const overload).

Iterates over indices [1, size()] and applies operation to each element until it returns false.

Template Parameters
Operationcallable type
Parameters
[in,out]operationfunctor to apply
Returns
false if traversal was stopped early, true otherwise

Definition at line 962 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::const_traverse_impl().

Referenced by TEST().

◆ traverse() [4/4]

template<typename T , class Compare = Aleph::less<T>>
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool Aleph::ArrayHeap< T, Compare >::traverse ( Operation &  operation)
inlinenoexcept

Traverse all elements.

Template Parameters
Operationcallable type
Parameters
[in,out]operationfunctor to apply
Returns
false if traversal was stopped early, true otherwise

Definition at line 976 of file tpl_arrayHeap.H.

References Aleph::ArrayHeap< T, Compare >::traverse_impl().

◆ traverse_impl()

template<typename T , class Compare = Aleph::less<T>>
template<class Operation >
bool Aleph::ArrayHeap< T, Compare >::traverse_impl ( Operation &  operation)
inlineprivate

◆ update()

template<typename T , class Compare = Aleph::less<T>>
void Aleph::ArrayHeap< T, Compare >::update ( T &  data)
inline

Update the priority of an element stored in the heap.

update(data) takes a reference to an element inside the heap, presumably modified, and updates its priority inside the heap.

The reference must have been obtained via a previous call to insert().

Parameters
[in]datareference to the element inside the heap to update
Exceptions
whatthe comparison throws. Then no item has moved, if the exchange of two items does not throw: the heap is as it was before the call, with data at its place, where its new priority may be out of order.
See also
insert()
Note
It is essential that data is a valid reference into this heap. Results are unpredictable (and probably fatal) if this is not the case.

Definition at line 806 of file tpl_arrayHeap.H.

References ah_underflow_error_if, FunctionalMethods< Container, T >::and, Aleph::ArrayHeap< T, Compare >::array, Aleph::ArrayHeap< T, Compare >::cmp, Aleph::ArrayHeap< T, Compare >::num_items, and Aleph::sift_down_up().

Referenced by TEST().

Member Data Documentation

◆ array

◆ array_allocated

template<typename T , class Compare = Aleph::less<T>>
bool Aleph::ArrayHeap< T, Compare >::array_allocated = false
mutableprivate

◆ cmp

◆ dim

◆ nothrow_cmp

template<typename T , class Compare = Aleph::less<T>>
constexpr bool Aleph::ArrayHeap< T, Compare >::nothrow_cmp
staticconstexprprivate
Initial value:
=
noexcept(static_cast<bool>(std::declval<Compare &>()(std::declval<T &>(),
std::declval<T &>())))

Definition at line 458 of file tpl_arrayHeap.H.

Referenced by Aleph::ArrayHeap< T, Compare >::remove().

◆ num_items


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