MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Sort.cpp
Go to the documentation of this file.
2
4
5void sort_span(std::span<double> data, SortingDirection direction, SortingAlgorithm algorithm)
6{
7 if (data.empty())
8 return;
9 execute(data.begin(), data.end(), double_comparator(direction), algorithm);
10}
11
12std::span<double> sort_span_into(std::span<const double> data, std::vector<double>& output_storage, SortingDirection direction, SortingAlgorithm algorithm)
13{
14 output_storage.assign(data.begin(), data.end());
15 sort_span(std::span<double>(output_storage), direction, algorithm);
16 return { output_storage.data(), output_storage.size() };
17}
18
19void sort_channels(std::vector<std::span<double>>& channels, SortingDirection direction, SortingAlgorithm algorithm)
20{
21 for (auto& ch : channels)
22 sort_span(ch, direction, algorithm);
23}
24
25std::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)
26{
27 output_storage.resize(channels.size());
28 std::vector<std::span<double>> out;
29 out.reserve(channels.size());
30 for (size_t i = 0; i < channels.size(); ++i)
31 out.push_back(sort_span_into(channels[i], output_storage[i], direction, algorithm));
32 return out;
33}
34
35std::vector<size_t> span_sort_indices(std::span<double> data, SortingDirection direction)
36{
37 std::vector<size_t> idx(data.size());
38 std::iota(idx.begin(), idx.end(), 0);
39 if (data.empty())
40 return idx;
41 const auto comp = double_comparator(direction);
42 std::ranges::sort(idx, [&](size_t a, size_t b) { return comp(data[a], data[b]); });
43 return idx;
44}
45
46std::vector<std::vector<size_t>> channels_sort_indices(const std::vector<std::span<double>>& channels, SortingDirection direction)
47{
48 std::vector<std::vector<size_t>> out;
49 out.reserve(channels.size());
50 for (const auto& ch : channels)
51 out.push_back(span_sort_indices(ch, direction));
52 return out;
53}
54
55} // namespace MayaFlux::Kinesis::Discrete
size_t a
size_t b
Discrete sequence sorting primitives for MayaFlux::Kinesis.
std::vector< size_t > span_sort_indices(std::span< double > data, SortingDirection direction)
Indices that would sort a span in the given direction.
Definition Sort.cpp:35
void sort_channels(std::vector< std::span< double > > &channels, SortingDirection direction, SortingAlgorithm algorithm)
Sort all channels in-place.
Definition Sort.cpp:19
void sort_span(std::span< double > data, SortingDirection direction, SortingAlgorithm algorithm)
Sort a single span in-place.
Definition Sort.cpp:5
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.
Definition Sort.cpp:12
std::vector< std::vector< size_t > > channels_sort_indices(const std::vector< std::span< double > > &channels, SortingDirection direction)
Per-channel sort indices.
Definition Sort.cpp:46
auto double_comparator(SortingDirection direction) noexcept
Direction-based comparator for doubles.
Definition Sort.hpp:68
void execute(Iterator begin, Iterator end, Comparator comp, SortingAlgorithm algorithm)
Execute a sorting algorithm on an iterator range.
Definition Sort.hpp:128
SortingAlgorithm
Available sorting algorithm backends.
Definition Sort.hpp:41
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.
Definition Sort.cpp:25
SortingDirection
Ascending or descending sort order.
Definition Sort.hpp:30