Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::arrayheap_detail Namespace Reference

Classes

struct  From_One
 The items of an array, numbered from 1. More...
 

Functions

template<class A >
constexpr void undo_sift_up (A ptr, size_t i, const size_t r)
 Take back down an item that sift_up() took up.
 
template<class A >
constexpr void undo_sift_down (A ptr, size_t i, const size_t l)
 Take back up an item that sift_down() took down.
 
template<class A , class Compare >
constexpr size_t sift_down (A ptr, const size_t l, const size_t r, Compare &cmp)
 Move the element at position l downwards to its place.
 
template<class A , class Compare >
constexpr decltype(auto) sift_up (A ptr, const size_t l, const size_t r, Compare &cmp)
 Move the element at position r upwards to its place.
 

Function Documentation

◆ sift_down()

template<class A , class Compare >
constexpr size_t Aleph::arrayheap_detail::sift_down ( A  ptr,
const size_t  l,
const size_t  r,
Compare &  cmp 
)
inlineconstexpr

Move the element at position l downwards to its place.

What sift_down() does, with its result.

Template Parameters
Athe items numbered from 1: a pointer to the entry 0 of the array, or a From_One.
Parameters
[in,out]ptrthe items of the heap.
[in]lleft boundary (inclusive) / starting index.
[in]rright boundary (inclusive).
[in]cmpcomparison criteria.
Returns
the entry where the element went: l, or one below it.
Exceptions
whatthe comparison throws, with the range as it was if the exchange of two items does not throw.

Definition at line 160 of file tpl_arrayHeap.H.

References Aleph::and, cmp(), l, Aleph::l_index(), r, and undo_sift_down().

Referenced by Aleph::faster_heapsort(), Aleph::heapsort(), Aleph::sift_down(), and Aleph::sift_down_up().

◆ sift_up()

template<class A , class Compare >
constexpr decltype(auto) Aleph::arrayheap_detail::sift_up ( A  ptr,
const size_t  l,
const size_t  r,
Compare &  cmp 
)
inlineconstexpr

Move the element at position r upwards to its place.

What sift_up() does, on the items of any array numbered from 1.

Template Parameters
Athe items numbered from 1: a pointer to the entry 0 of the array, or a From_One.
Parameters
[in,out]ptrthe items of the heap.
[in]lleft boundary (inclusive).
[in]rright boundary (inclusive) / starting index.
[in]cmpcomparison criteria.
Returns
a mutable reference to the element after it has been placed.
Exceptions
whatthe comparison throws, with the range as it was if the exchange of two items does not throw.

Definition at line 209 of file tpl_arrayHeap.H.

References Aleph::and, cmp(), l, r, Aleph::u_index(), and undo_sift_up().

Referenced by Aleph::heapsort(), and Aleph::sift_up().

◆ undo_sift_down()

template<class A >
constexpr void Aleph::arrayheap_detail::undo_sift_down ( A  ptr,
size_t  i,
const size_t  l 
)
inlineconstexpr

Take back up an item that sift_down() took down.

Template Parameters
Athe items numbered from 1: a pointer to the entry 0 of the array, or a From_One.
Parameters
[in,out]ptrthe items of the heap.
[in]ithe entry where the item is.
[in]lthe entry where it was: i, or one above it.

Definition at line 138 of file tpl_arrayHeap.H.

References l, and Aleph::u_index().

Referenced by sift_down(), and Aleph::sift_down_up().

◆ undo_sift_up()

template<class A >
constexpr void Aleph::arrayheap_detail::undo_sift_up ( A  ptr,
size_t  i,
const size_t  r 
)
inlineconstexpr

Take back down an item that sift_up() took up.

The item is exchanged with each item of its way, which the indexes give: the ancestors of an entry are its index without its last bits.

Template Parameters
Athe items numbered from 1: a pointer to the entry 0 of the array, or a From_One.
Parameters
[in,out]ptrthe items of the heap.
[in]ithe entry where the item is.
[in]rthe entry where it was: i, or one below it.

Definition at line 118 of file tpl_arrayHeap.H.

References r.

Referenced by sift_up().