15#if HX_USE_MACROS_WITH_MODULE
16#error Header does not provide macros alone.
24#include "detail/hxsort_detail.hpp"
33template<hxrandom_iterator_concept_ iterator_t_,
typename less_t_>
37 if(begin_ == end_) {
return; }
39 for(iterator_t_ i_ = begin_r_, j_ = begin_r_ + ptrdiff_t{1}; j_ < end_; i_ = j_, ++j_) {
43 while(begin_r_ < i_ && less_(t_, *(i_ - ptrdiff_t{1}))) {
44 *i_ =
hxmove(*(i_ - ptrdiff_t{1}));
55template<hxsorted_iterator_concept_ iterator_t_>
64template<hxrandom_iterator_concept_ iterator_t_,
typename less_t_>
66 if(begin_ == end_) {
return; }
67 hxdetail_::hxmake_heap_<iterator_t_>(begin_, end_, less_);
69 for(iterator_t_ it_ = end_ - ptrdiff_t{1}; begin_r_ < it_; --it_) {
71 hxdetail_::hxheapsort_heapify_<iterator_t_>(begin_r_, begin_r_, it_, less_);
77template<hxsorted_iterator_concept_ iterator_t_>
87template<hxrandom_iterator_concept_ iterator_t_,
typename less_t_>
89 const hxsize_t size_ = end_ - begin_;
90 hxdetail_::hxintro_sort_<iterator_t_>(begin_, end_, less_,
91 size_ > 0 ? 2 *
hxlog2i(
static_cast<uint32_t
>(size_)) : 0);
94template<hxsorted_iterator_concept_ iterator_t_>
96 const hxsize_t size_ = end_ - begin_;
97 hxdetail_::hxintro_sort_<iterator_t_>(begin_, end_,
hxkey_less_t<
decltype(*begin_)>{},
98 size_ > 0 ? 2 *
hxlog2i(
static_cast<uint32_t
>(size_)) : 0);
hxkey_less_t<T> - A constexpr callable that returns true if the first object is less than the second.
Definition hxkey.hpp:91
User-specializable key-equal, key-less, and key-hash callables.
Read-only range utilities for libhatchet.
#define hxinline
hxinline - Force a function to be inlined into its callers.
Definition hxsettings.h:125
#define hxattr_flatten
hxattr_flatten - Inline every call inside a function's body into it, recursively, regardless of the c...
Definition hxsettings.h:90
#define hxconstexpr
hxconstexpr - Enables C++23 compatable constexpr usage for functions as that has support for destruct...
Definition hxsettings.h:266
constexpr void hxsort(iterator_t_ begin_, iterator_t_ end_, const less_t_ &less_)
hxsort - A general purpose sort routine using T::T(&&), T::~T(), T::operator=(&&),...
Definition hxsort.hpp:88
constexpr void hxheapsort(iterator_t_ begin_, iterator_t_ end_, const less_t_ &less_)
hxheapsort - Sorts the elements in the range [begin, end) using the heapsort algorithm.
Definition hxsort.hpp:65
HX_NS_BEGIN_ constexpr void hxinsertion_sort(iterator_t_ begin_, iterator_t_ end_, const less_t_ &less_)
hxinsertion_sort - Sorts the elements in the range [begin, end) in comparison order using the inserti...
Definition hxsort.hpp:35
typename hxrestrict_t_< T >::type hxrestrict_t
hxrestrict_t - Adds the __restrict keyword to C++ pointers.
Definition hxutility.h:287
constexpr void hxswap(T &x_, T &y_)
hxswap - Exchanges the contents of x and y using a temporary.
Definition hxutility.h:414
constexpr hxremove_reference_t< T > && hxmove(T &&t_)
hxmove - Implements std::move.
Definition hxutility.h:407
int hxlog2i(uint32_t i_)
hxlog2i - Returns log2(n) as an integer which is the power of 2 of the largest bit in n.
Definition hxutility.h:312
Provides core macros, memory management and feature detection.
ptrdiff_t hxsize_t
hxsize_t - A signed size type, same as ssize_t or ptrdiff_t.
Definition libhatchet.h:207