49# ifndef TPL_DYNARRAYHEAP_H
50# define TPL_DYNARRAYHEAP_H
69 template <
typename T,
class Compare>
73 for (
size_t p, i = r; i >
l; i = p)
97 template <
typename T,
class Compare>
112 T *
ac = &a.access(c);
115 T *
ac1 = &a.access(c + 1);
123 T &
ai = a.access(i);
141 template <
typename T,
class Compare = Aleph::less<T>>
153 static size_t r_index(
const size_t & i)
noexcept
182 return array.access(1);
190 return array.access(1);
205 return array.access(pos);
217 return array.access(pos);
238 return array.access(pos);
246 return array.access(pos);
312 if (
h.num_items != 0)
332 template <
class Operation>
341 template <
class Operation>
347 template <
class Operation>
353 template <
class Operation>
#define Args_Ctor(Name, Type)
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Dynamic heap (priority queue) backed by DynArray.
T & insert_direct(T &&key)
Move overload of insert_direct().
static size_t r_index(const size_t &i) noexcept
DynArrayHeap(Compare cmp_fct=Compare())
Default constructor.
T & put(T &&key)
Alias for insert() (move overload).
void reserve(size_t n)
Ensure the underlying array has capacity for at least n elements.
constexpr bool is_empty() const noexcept
Return true if the heap is empty.
T getMin()
Remove and return the top element.
bool traverse(Operation &operation)
Traverse all elements in the heap.
T & put(const T &key)
Alias for insert().
bool traverse(Operation &operation) const
T & append(const T &key)
Alias for insert().
bool traverse(Operation &&operation=Operation()) const
T & insert(const T &key)
Insert a copy of key into the heap.
bool traverse(Operation &&operation=Operation())
T & insert(T &&key)
Insert a key by moving it into the heap.
T & top()
Return the element with highest priority (the heap top).
T & insert_direct(const T &key)
Insert by directly indexing into the backing array.
const T & top() const
Const overload of top().
T & append(T &&key)
Alias for insert() (move overload).
constexpr size_t size() const noexcept
Return the number of elements.
Iterator on the items of array.
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
size_t size() const noexcept
Return the current dimension of array.
Equality test for containers.
Common methods to the Aleph-w ( ) containers.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
size_t l_index(const size_t i)
Map a binary heap index to the index of its left child.
void sift_down(T *ptr, const size_t l, const size_t r, Compare &cmp)
Restore the heap property by moving the element at position l downwards.
std::decay_t< typename HeadC::Item_Type > T
size_t u_index(const size_t &i)
Map a binary heap index to the index of its parent.
T & sift_up(T *ptr, const size_t l, const size_t r, Compare &cmp)
Restore the heap property by moving the element at position r upwards.
DynList< T > maps(const C &c, Op op)
Classic map operation.
typename DynArray< T >::Iterator Base
bool has_curr() const noexcept
Iterator(const DynArrayHeap &h) noexcept
long get_pos() const noexcept
Generic list of items stored in a container.
Lazy and scalable dynamic array implementation.