70 return [direction](
double a,
double b)
noexcept ->
bool {
82 requires requires(T v) { { std::abs(v) } -> std::convertible_to<double>; }
85 return [direction](
const T&
a,
const T&
b)
noexcept ->
bool {
87 ? std::abs(
a) < std::abs(
b)
88 : std::abs(
a) > std::abs(
b);
100template <
typename Container,
typename Comparator>
101[[nodiscard]] std::vector<size_t>
sort_indices(
const Container& container, Comparator comp)
103 std::vector<size_t> idx(container.size());
104 std::iota(idx.begin(), idx.end(), 0);
105 std::ranges::sort(idx, [&](
size_t a,
size_t b) {
106 return comp(container[
a], container[
b]);
127template <std::random_access_iterator Iterator,
typename Comparator>
132 std::ranges::stable_sort(begin, end, comp);
136 const auto dist = std::distance(begin, end);
138 std::partial_sort(begin, begin + dist / 2, end, comp);
143 const auto dist = std::distance(begin, end);
145 std::nth_element(begin, begin + dist / 2, end, comp);
150 std::make_heap(begin, end, comp);
151 std::sort_heap(begin, end, comp);
155 MayaFlux::Parallel::sort(MayaFlux::Parallel::par_unseq, begin, end, comp);
160 std::ranges::sort(begin, end, comp);
176 std::span<double> data,
189 std::span<const double> data,
190 std::vector<double>& output_storage,
201 std::vector<std::span<double>>& channels,
214 const std::vector<std::span<const double>>& channels,
215 std::vector<std::vector<double>>& output_storage,
230 std::span<double> data,
240 const std::vector<std::span<double>>& channels,
std::vector< size_t > span_sort_indices(std::span< double > data, SortingDirection direction)
Indices that would sort a span in the given direction.
void sort_channels(std::vector< std::span< double > > &channels, SortingDirection direction, SortingAlgorithm algorithm)
Sort all channels in-place.
void sort_span(std::span< double > data, SortingDirection direction, SortingAlgorithm algorithm)
Sort a single span in-place.
std::span< double > sort_span_into(std::span< const double > data, std::vector< double > &output_storage, SortingDirection direction, SortingAlgorithm algorithm)
Sort a span into a caller-owned output buffer.
auto magnitude_comparator(SortingDirection direction) noexcept
Magnitude-based comparator for complex-like types.
std::vector< std::vector< size_t > > channels_sort_indices(const std::vector< std::span< double > > &channels, SortingDirection direction)
Per-channel sort indices.
auto double_comparator(SortingDirection direction) noexcept
Direction-based comparator for doubles.
void execute(Iterator begin, Iterator end, Comparator comp, SortingAlgorithm algorithm)
Execute a sorting algorithm on an iterator range.
SortingAlgorithm
Available sorting algorithm backends.
@ QUICK_OPTIMIZED
Not yet implemented, falls back to STANDARD.
@ STABLE
std::ranges::stable_sort — preserves equal-element order
@ GPU_ACCELERATED
Reserved for Vulkan compute integration.
@ EIGEN_OPTIMIZED
Reserved for Eigen-specific use.
@ RADIX
Not yet implemented, falls back to STANDARD.
@ STANDARD
std::ranges::sort
@ COUNTING
Not yet implemented, falls back to STANDARD.
@ LAZY_STREAMING
Reserved for Vruta/Kriya coroutine integration.
@ HEAP
Heap sort via make_heap / sort_heap.
@ MERGE_EXTERNAL
Not yet implemented, falls back to STANDARD.
@ NTH_ELEMENT
std::nth_element — partitions at midpoint
@ PREDICTIVE_ML
Reserved for ML-guided sort.
@ PARALLEL
MayaFlux::Parallel::sort with par_unseq.
@ BUCKET
Not yet implemented, falls back to STANDARD.
@ PARTIAL
std::partial_sort — sorts first half by default
std::vector< size_t > sort_indices(const Container &container, Comparator comp)
Generic sort-index generator for any random-access container.
std::vector< std::span< double > > sort_channels_into(const std::vector< std::span< const double > > &channels, std::vector< std::vector< double > > &output_storage, SortingDirection direction, SortingAlgorithm algorithm)
Sort all channels into caller-owned output buffers.
SortingDirection
Ascending or descending sort order.
@ BIDIRECTIONAL
Sort with both directions (for special algorithms)
@ CUSTOM
Use custom comparator function.