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

Dynamic heap (priority queue) backed by DynArray. More...

#include <tpl_dynArrayHeap.H>

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

Classes

class  Iterator
 Iterator on the items of the heap, in the order of its array, which is not the sorted one. More...
 

Public Types

using Item_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

 DynArrayHeap (Compare cmp_fct=Compare())
 Default constructor.
 
template<template< typename > class List>
 DynArrayHeap (const List< T > &l)
 
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
 DynArrayHeap (It b, It e)
 
 DynArrayHeap (std::initializer_list< T > l)
 
template<typename ... Args>
 DynArrayHeap (const T &item, Args &... args)
 
template<typename ... Args>
 DynArrayHeap (T &&item, Args &... args)
 
 DynArrayHeap (const DynArrayHeap &other)=default
 Copy the elements and the comparator of another heap.
 
 DynArrayHeap (DynArrayHeap &&other) noexcept(std::is_nothrow_move_constructible_v< DynArray< T > > and std::is_nothrow_copy_constructible_v< Compare >)
 Take the elements of another heap, which is left empty.
 
DynArrayHeap & operator= (const DynArrayHeap &other)=default
 Copy the elements and the comparator of another heap.
 
DynArrayHeap & operator= (DynArrayHeap &&other) noexcept(noexcept(swap(other)))
 Exchange this heap with another, which is left with the previous elements of this one.
 
void swap (DynArrayHeap &other) noexcept(std::is_nothrow_swappable_v< T > and std::is_nothrow_swappable_v< Compare >)
 Exchange in O(1) the elements and the comparators of this heap and another.
 
T & top ()
 Return the element with highest priority (the heap top).
 
const T & top () const
 Const overload of top().
 
T & insert (const T &key)
 Insert a copy of key into the heap.
 
T & insert (T &&key)
 Insert a key by moving it into the heap.
 
void reserve (size_t n)
 Ensure the underlying array has capacity for at least n elements.
 
T & insert_direct (const T &key)
 Insert by directly indexing into the backing array.
 
T & insert_direct (T &&key)
 Move overload of insert_direct().
 
T & put (const T &key)
 Alias for insert().
 
T & put (T &&key)
 Alias for insert() (move overload).
 
T & append (const T &key)
 Alias for insert().
 
T & append (T &&key)
 Alias for insert() (move overload).
 
T getMin ()
 Remove and return the top element.
 
T get ()
 See getMin().
 
T getMax ()
 See getMin(); useful if priority order is inverted.
 
constexpr size_t size () const noexcept
 Return the number of elements.
 
constexpr bool is_empty () const noexcept
 Return true if the heap is empty.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool traverse (Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
 Traverse all elements in the heap.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool traverse (Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, const T &>
bool traverse (Operation &&operation=Operation()) const
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, T &>
bool traverse (Operation &&operation=Operation())
 
- 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

T & enter (T &key, T &item, T &place, const size_t r)
 Take to its place the item moved from the key of an insertion.
 

Static Private Member Functions

static size_t r_index (const size_t &i) noexcept
 

Private Attributes

DynArray< T > array
 
size_t num_items = 0
 
Compare 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::DynArrayHeap< T, Compare >

Dynamic heap (priority queue) backed by DynArray.

Template Parameters
Telement type stored in the heap
Comparecomparator defining the priority order
See also
BinHeap DynBinHeap ArrayHeap

Definition at line 262 of file tpl_dynArrayHeap.H.

Member Typedef Documentation

◆ Const_Iterator

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

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

Definition at line 672 of file tpl_dynArrayHeap.H.

◆ Item_Type

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

Definition at line 315 of file tpl_dynArrayHeap.H.

Constructor & Destructor Documentation

◆ DynArrayHeap() [1/8]

template<typename T , class Compare = Aleph::less<T>>
Aleph::DynArrayHeap< T, Compare >::DynArrayHeap ( Compare  cmp_fct = Compare())
inline

Default constructor.

Definition at line 318 of file tpl_dynArrayHeap.H.

◆ DynArrayHeap() [2/8]

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

Definition at line 323 of file tpl_dynArrayHeap.H.

◆ DynArrayHeap() [3/8]

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

Definition at line 323 of file tpl_dynArrayHeap.H.

◆ DynArrayHeap() [4/8]

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

Definition at line 323 of file tpl_dynArrayHeap.H.

◆ DynArrayHeap() [5/8]

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

Definition at line 325 of file tpl_dynArrayHeap.H.

◆ DynArrayHeap() [6/8]

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

Definition at line 325 of file tpl_dynArrayHeap.H.

◆ DynArrayHeap() [7/8]

template<typename T , class Compare = Aleph::less<T>>
Aleph::DynArrayHeap< T, Compare >::DynArrayHeap ( const DynArrayHeap< T, Compare > &  other)
default

Copy the elements and the comparator of another heap.

Parameters
[in]otherheap to copy.

◆ DynArrayHeap() [8/8]

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

Take the elements of another heap, which is left empty.

The implicit move took the array but copied the number of items: the moved-from heap then read entries that it no longer had. The comparator is copied, since the heap left empty still uses it.

Parameters
[in,out]otherheap to move from.

Definition at line 340 of file tpl_dynArrayHeap.H.

Member Function Documentation

◆ append() [1/2]

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

Alias for insert().

Definition at line 515 of file tpl_dynArrayHeap.H.

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

Referenced by TEST().

◆ append() [2/2]

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

Alias for insert() (move overload).

Definition at line 518 of file tpl_dynArrayHeap.H.

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

◆ enter()

template<typename T , class Compare = Aleph::less<T>>
T & Aleph::DynArrayHeap< T, Compare >::enter ( T &  key,
T &  item,
T &  place,
const size_t  r 
)
inlineprivate

Take to its place the item moved from the key of an insertion.

The key is moved before the comparisons, which thus see it as the move leaves it when it is an item of this heap. If a comparison throws, the key takes its item back by a move assignment, and the heap is as it was.

Parameters
[in,out]keythe key, moved from.
[in,out]itemwhat was moved from the key.
[in,out]placethe entry r of the array, where the item enters.
[in]rthe index where the item enters.
Returns
the item, in its place.
Exceptions
whatthe comparison throws, with the heap and the key as they were; or, if the move assignment that gives the key its item back throws too, what that assignment throws, with the item lost, as when a move of the items throws in the sifts.

Definition at line 296 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::cmp, Aleph::DynArrayHeap< T, Compare >::num_items, r, Aleph::dynarrayheap_detail::shift(), and Aleph::dynarrayheap_detail::up_index().

Referenced by Aleph::DynArrayHeap< T, Compare >::insert(), and Aleph::DynArrayHeap< T, Compare >::insert_direct().

◆ get()

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

See getMin().

Definition at line 550 of file tpl_dynArrayHeap.H.

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

Referenced by TEST().

◆ getMax()

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

See getMin(); useful if priority order is inverted.

Definition at line 556 of file tpl_dynArrayHeap.H.

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

Referenced by TEST().

◆ getMin()

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

Remove and return the top element.

With the default comparator (Aleph::less<T>), this removes and returns the smallest element.

Exceptions
underflow_errorif the heap is empty.
whatthe comparison throws, with the heap as it was.

Definition at line 528 of file tpl_dynArrayHeap.H.

References ah_underflow_error_if, Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::cmp, Aleph::dynarrayheap_detail::down_index(), Aleph::DynArrayHeap< T, Compare >::num_items, root(), and Aleph::dynarrayheap_detail::shift().

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

◆ insert() [1/2]

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

Insert a copy of key into the heap.

Parameters
[in]keyKey to insert.
Returns
A modifiable reference to the stored element.
Exceptions
whatthe comparison, the copy of key or its place throw, with the heap as it was.
Note
This reference points to an element inside the heap and can become invalid after further insertions/removals.

Definition at line 428 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::cmp, Aleph::DynArrayHeap< T, Compare >::num_items, r, Aleph::dynarrayheap_detail::shift(), and Aleph::dynarrayheap_detail::up_index().

Referenced by Aleph::DynArrayHeap< T, Compare >::append(), Aleph::DynArrayHeap< T, Compare >::append(), Moved_From_Case< DynArrayHeap< int > >::make(), Aleph::DynArrayHeap< T, Compare >::put(), Aleph::DynArrayHeap< T, Compare >::put(), TEST(), 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::DynArrayHeap< T, Compare >::insert ( T &&  key)
inline

Insert a key by moving it into the heap.

Parameters
[in]keyKey to move.
Returns
A modifiable reference to the stored element.
Exceptions
whatthe place of key throws, with the heap and key as they were; and what the comparison throws, with the heap as it was 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, as when a move of the items throws in the sifts.
Note
key may be an item of this heap. The move, which comes before the comparisons, changes that item where it is, as any change through a reference to it does, and the heap does not put that item in order again: it is left in order only if the item still is, where it is.

Definition at line 458 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::enter(), Aleph::DynArrayHeap< T, Compare >::num_items, and r.

◆ insert_direct() [1/2]

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

Insert by directly indexing into the backing array.

This variant uses operator() instead of touch().

Exceptions
whatthe comparison or the copy of key throw, with the heap as it was.

Definition at line 483 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::cmp, Aleph::DynArrayHeap< T, Compare >::num_items, r, Aleph::dynarrayheap_detail::shift(), and Aleph::dynarrayheap_detail::up_index().

Referenced by TEST(), and TEST().

◆ insert_direct() [2/2]

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

Move overload of insert_direct().

Exceptions
whatthe comparison throws, with the heap as it was and key too, which takes its item back by a move assignment, as in insert(T &&).
Note
key may be an item of this heap, as in insert(T &&).

Definition at line 501 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::enter(), Aleph::DynArrayHeap< T, Compare >::num_items, and r.

◆ is_empty()

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

Return true if the heap is empty.

Definition at line 565 of file tpl_dynArrayHeap.H.

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

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

◆ operator=() [1/2]

template<typename T , class Compare = Aleph::less<T>>
DynArrayHeap & Aleph::DynArrayHeap< T, Compare >::operator= ( const DynArrayHeap< T, Compare > &  other)
default

Copy the elements and the comparator of another heap.

Parameters
[in]otherheap to copy.
Returns
this heap.

◆ operator=() [2/2]

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

Exchange this heap with another, which is left with the previous elements of this one.

Parameters
[in,out]otherheap to move from.
Returns
this heap.

Definition at line 358 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::swap().

◆ put() [1/2]

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

Alias for insert().

Definition at line 509 of file tpl_dynArrayHeap.H.

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

Referenced by TEST().

◆ put() [2/2]

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

Alias for insert() (move overload).

Definition at line 512 of file tpl_dynArrayHeap.H.

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

◆ r_index()

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

Definition at line 272 of file tpl_dynArrayHeap.H.

◆ reserve()

template<typename T , class Compare = Aleph::less<T>>
void Aleph::DynArrayHeap< T, Compare >::reserve ( size_t  n)
inline

Ensure the underlying array has capacity for at least n elements.

Exceptions
out_of_range_errorif n is smaller than the current size.

Definition at line 470 of file tpl_dynArrayHeap.H.

References ah_out_of_range_error_if, Aleph::DynArrayHeap< T, Compare >::array, and Aleph::DynArrayHeap< T, Compare >::num_items.

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

◆ size()

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

Return the number of elements.

Definition at line 562 of file tpl_dynArrayHeap.H.

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

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

◆ swap()

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

Exchange in O(1) the elements and the comparators of this heap and another.

Parameters
[in,out]otherheap to exchange with.
Exceptions
whatswapping the comparators, or the default values of the arrays, throws. The comparators go first; if the swap of the arrays throws, they are exchanged back, and both heaps are left as they were, if the swap that threw left its arguments as they were. If the swap that puts the comparators back throws too, both heaps can only be destroyed or assigned.

Definition at line 374 of file tpl_dynArrayHeap.H.

References Aleph::DynArrayHeap< T, Compare >::array, Aleph::DynArrayHeap< T, Compare >::cmp, Aleph::DynArrayHeap< T, Compare >::num_items, and Aleph::DynArrayHeap< T, Compare >::swap().

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

◆ top() [1/2]

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

Return the element with highest priority (the heap top).

With the default comparator (Aleph::less<T>), this is the smallest element.

Exceptions
underflow_errorif the heap is empty.

Definition at line 403 of file tpl_dynArrayHeap.H.

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

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

◆ top() [2/2]

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

◆ traverse() [1/4]

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

Definition at line 711 of file tpl_dynArrayHeap.H.

◆ traverse() [2/4]

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

Definition at line 704 of file tpl_dynArrayHeap.H.

◆ traverse() [3/4]

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

◆ traverse() [4/4]

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

Traverse all elements in the heap.

Iteration order is the internal heap array order (not sorted).

The traversal stops early if the operation returns false.

Definition at line 682 of file tpl_dynArrayHeap.H.

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

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

Member Data Documentation

◆ array

◆ cmp

◆ num_items


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