137#define List_Sort(List) \
145 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
146 List<T> sort(const List<T> & c, Cmp & cmp) \
148 List<T> ret_val = c; \
149 mergesort<List, T, Cmp>(ret_val, cmp); \
155 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
156 List<T> sort(const List<T> & c, Cmp && cmp = Cmp()) \
158 return sort<T, Cmp>(c, cmp); \
168 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
169 List<T> sort(List<T> && c, Cmp & cmp) \
171 mergesort<List, T, Cmp>(c, cmp); \
172 return std::move(c); \
177 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
178 List<T> sort(List<T> && c, Cmp && cmp = Cmp()) \
180 return sort<T, Cmp>(std::move(c), cmp); \
190 template <typename T, class Cmp = Aleph::less<T>> inline \
191 List<T> & in_place_sort(List<T> & c, Cmp & cmp) \
193 mergeinsertsort(c, cmp); \
199 template <typename T, class Cmp = Aleph::less<T>> inline \
200 List<T> & in_place_sort(List<T> & c, Cmp && cmp = Cmp()) \
202 return in_place_sort<T, Cmp>(c, cmp); \
225 template<
typename T,
class Cmp = Aleph::less<T>>
246 template<
typename T,
class Cmp = Aleph::less<T>>
257 template<
typename T,
class Cmp = Aleph::less<T>>
269 template<
typename T,
class Cmp = Aleph::less<T>>
298 class Cmp = std::less<typename Container::value_type>>
319 template<
typename T,
class Cmp = Aleph::less<T>>
330 template<
typename T,
class Cmp = Aleph::less<T>>
350 template<
typename T,
template <
typename>
class C>
353 using P = std::pair<T, size_t>;
359 const size_t n = c.
size();
362 for (
size_t i = 0; i < n; ++i)
366 return c(
i1) < c(
i2);
370 for (
size_t i = 0; i < n; ++i)
376 template<
template <
typename Type>
class List>
389 return items(
i1) < items(
i2);
393 for (
size_t i = 0; i < n; ++i)
401 const size_t n = c.
size();
404 for (
size_t i = 0; i < n; ++i)
408 return c(
i1) < c(
i2);
412 for (
size_t i = 0; i < n; ++i)
415 ret(idx) =
P(c(idx), i);
421 template<
template <
typename Type>
class List>
434 return items(
i1) < items(
i2);
438 for (
size_t i = 0; i < n; ++i)
441 ret(idx) =
P(items(idx), i);
456 using P = std::pair<T, size_t>;
462 const size_t n = c.
size();
464 for (
size_t i = 0; i < n; ++i)
468 return c(
i1) < c(
i2);
472 for (
size_t i = 0; i < n; ++i)
480 const size_t n = c.
size();
482 for (
size_t i = 0; i < n; ++i)
486 return c(
i1) < c(
i2);
490 for (
size_t i = 0; i < n; ++i)
493 ret(idx) =
P(c(idx), i);
611 return func.list_pair_ranks(
l);
624 return func.list_pair_ranks(
l);
665 template<
typename C,
typename...
Args,
666 typename Cmp = std::less<typename C::value_type>>
670 const size_t n = first.size();
676 <<
"all arrays must have the same size";
678 std::vector<size_t>
indices(n);
683 return cmp(first[i1], first[i2]);
689 for (
size_t i = 0; i < n; ++i)
Exception handling system with formatted messages for Aleph-w.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Zip iterators and functional operations for multiple containers.
Functional programming utilities for Aleph-w containers.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Dynamic doubly linked list with O(1) size and bidirectional access.
Dynamic singly linked list with functional programming support.
size_t size() const noexcept
Count the number of elements of the list.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
auto pair_ranks(const Array< T > &c)
Computes (value, rank) pairs for each element in an Array.
void in_place_multisort_arrays(Cmp cmp, C &first, Args &... args)
Sorts multiple arrays in place, using the first array as the key.
std::decay_t< typename HeadC::Item_Type > T
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
DynArray< T > & in_place_sort(DynArray< T > &c, Cmp cmp=Cmp())
Sorts a DynArray in place.
DynList< std::pair< size_t, typename Container::Key_Type > > indexes(const Container &c)
Return pairs of (index, key).
Array< size_t > ranks(const Array< T > &array)
Computes the rank of each element in an Array.
Container stdsort(const Container &c, Cmp cmp=Cmp())
Sorts an STL-compatible container using std::sort.
void next()
Advance all underlying iterators (bounds-checked).
DynList< T > maps(const C &c, Op op)
Classic map operation.
void quicksort_op(C< T > &a, const Compare &cmp=Compare(), const size_t threshold=Quicksort_Threshold)
Optimized quicksort for containers using operator().
Dynamic doubly linked list implementation.
Comprehensive sorting algorithms and search utilities for Aleph-w.