144#define List_Sort(List) \
152 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
153 List<T> sort(const List<T> & c, Cmp & cmp) \
155 List<T> ret_val = c; \
156 mergesort<List, T, Cmp>(ret_val, cmp); \
162 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
163 List<T> sort(const List<T> & c, Cmp && cmp = Cmp()) \
165 return sort<T, Cmp>(c, cmp); \
175 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
176 List<T> sort(List<T> && c, Cmp & cmp) \
178 mergesort<List, T, Cmp>(c, cmp); \
179 return std::move(c); \
184 template <typename T, class Cmp = Aleph::less<T>> [[nodiscard]] inline \
185 List<T> sort(List<T> && c, Cmp && cmp = Cmp()) \
187 return sort<T, Cmp>(std::move(c), cmp); \
197 template <typename T, class Cmp = Aleph::less<T>> inline \
198 List<T> & in_place_sort(List<T> & c, Cmp & cmp) \
200 mergeinsertsort(c, cmp); \
206 template <typename T, class Cmp = Aleph::less<T>> inline \
207 List<T> & in_place_sort(List<T> & c, Cmp && cmp = Cmp()) \
209 return in_place_sort<T, Cmp>(c, cmp); \
232 template<
typename T,
class Cmp = Aleph::less<T>>
253 template<
typename T,
class Cmp = Aleph::less<T>>
264 template<
typename T,
class Cmp = Aleph::less<T>>
276 template<
typename T,
class Cmp = Aleph::less<T>>
305 class Cmp = std::less<typename Container::value_type>>
326 template<
typename T,
class Cmp = Aleph::less<T>>
337 template<
typename T,
class Cmp = Aleph::less<T>>
386 const Compare &
cmp = Compare())
434 const Compare &
cmp = Compare())
451 template<
typename T,
template <
typename>
class C>
454 using P = std::pair<T, size_t>;
471 const size_t n = c.size();
474 for (
size_t i = 0; i < n; ++i)
478 return c(
i1) < c(
i2);
482 for (
size_t i = 0; i < n; ++i)
501 template<
template <
typename Type>
class List>
507 c.for_each([&items, &n, &
indexes](
auto k)
514 return items(
i1) < items(
i2);
518 for (
size_t i = 0; i < n; ++i)
538 const size_t n = c.size();
541 for (
size_t i = 0; i < n; ++i)
545 return c(
i1) < c(
i2);
549 for (
size_t i = 0; i < n; ++i)
552 ret(idx) =
P(c(idx), i);
571 template<
template <
typename Type>
class List>
577 c.for_each([&items, &n, &
indexes](
auto k)
584 return items(
i1) < items(
i2);
588 for (
size_t i = 0; i < n; ++i)
591 ret(idx) =
P(items(idx), i);
606 using P = std::pair<T, size_t>;
624 const size_t n = c.
size();
626 for (
size_t i = 0; i < n; ++i)
630 return c(
i1) < c(
i2);
634 for (
size_t i = 0; i < n; ++i)
654 const size_t n = c.
size();
656 for (
size_t i = 0; i < n; ++i)
660 return c(
i1) < c(
i2);
664 for (
size_t i = 0; i < n; ++i)
667 ret(idx) =
P(c(idx), i);
785 return func.list_pair_ranks(
l);
798 return func.list_pair_ranks(
l);
841 template<
typename C,
typename...
Args,
842 typename Cmp = std::less<typename C::value_type>>
846 const size_t n = first.size();
852 <<
"all arrays must have the same size";
854 std::vector<size_t>
indices(n);
855 std::iota(
indices.begin(),
indices.end(),
static_cast<size_t>(0));
859 return cmp(first[
i1], first[
i2]);
885 for (
size_t i = 0; i < n; ++i)
888 const size_t j =
perm[i];
889 swap(first[i], first[j]);
895 template<
typename C,
typename...
Args,
896 typename Cmp = std::less<typename C::value_type>>
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.
static Array create(size_t n)
Create an array with n logical elements.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Node belonging to a double circular linked list with header node.
Dynamic doubly linked list with O(1) size and bidirectional access.
Doubly-linked list (defined in tpl_dynList.H).
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Array< size_t > stable_build_index(const C &a, const Compare &cmp=Compare())
Build a stable index array for indirect sorting.
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.
Array< size_t > stable_argsort(const C &a, const Compare &cmp=Compare())
Return stable sorted-order indices for an array-like container.
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.
Array< size_t > build_index(const C &a, const Compare &cmp=Compare())
Build an index array for indirect sorting.
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).
void mergesort(T *a, const long l, const long r, Array< T > &buf, Compare cmp)
Sort an array using merge sort with a reusable buffer.
Array< size_t > ranks(const Array< T > &array)
Computes the rank of each element in an Array.
Array< size_t > argsort(const C &a, const Compare &cmp=Compare())
Return indices that visit an array-like container in sorted order.
Container stdsort(const Container &c, Cmp cmp=Cmp())
Sorts an STL-compatible container using std::sort.
void introsort(T *a, const long l, const long r, const Compare &cmp=Compare())
Sort an array using introsort (introspective sort).
void in_place_multisort_arrays(Cmp cmp, const bool stable, C &first, Args &... args)
Sorts multiple arrays in place, using the first array as the key.
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.