53template <ComputeData InputType = Kakshya::DataVariant, ComputeData OutputType = InputType>
109 return "StandardSorter";
148 if (
name ==
"algorithm") {
149 if (
auto alg_result = safe_any_cast<SortingAlgorithm>(
value)) {
153 if (
auto str_result = safe_any_cast<std::string>(
value)) {
154 auto algorithm_enum = Reflect::string_to_enum_case_insensitive<SortingAlgorithm>(*str_result.value);
155 if (algorithm_enum) {
161 if (
name ==
"chunk_size") {
162 if (
auto size_result = safe_any_cast<size_t>(
value)) {
172 if (
name ==
"algorithm") {
175 if (
name ==
"chunk_size") {
191 std::vector<std::vector<double>> working_buffer;
198 result.metadata =
input.metadata;
199 result.container =
input.container;
200 result.metadata[
"sort_type"] =
"copy";
204 }
catch (
const std::exception& e) {
206 error_result.metadata =
input.metadata;
207 error_result.container =
input.container;
208 error_result.metadata[
"error"] = std::string(
"Sorting failed: ") + e.what();
218 if constexpr (std::same_as<InputType, OutputType>) {
232 if constexpr (std::same_as<OutputType, std::vector<size_t>>) {
235 result.metadata =
input.metadata;
236 result.metadata[
"sort_type"] =
"indices_only";
250 if constexpr (std::same_as<InputType, OutputType>) {
267 result.metadata[
"sort_type"] =
"parallel";
303 std::vector<InputType> chunks;
306 std::vector<std::vector<double>> chunk_data;
309 for (
size_t ch = 0; ch <
channels.size(); ++ch) {
311 auto chunk_span =
channels[ch].subspan(start, end - start);
313 chunk_data[ch].assign(chunk_span.begin(), chunk_span.end());
317 chunks.push_back(OperationHelper::reconstruct_from_double<InputType>(chunk_data, info));
344 result.metadata = original_input.metadata;
345 result.metadata[
"sort_type"] =
"chunked_merged";
347 if constexpr (std::same_as<InputType, OutputType>) {
348 if (chunks.empty()) {
353 std::vector<std::vector<double>> merged_channels;
355 for (
const auto& chunk : chunks) {
358 if (merged_channels.empty()) {
359 merged_channels.resize(chunk_channels.size());
362 for (
size_t ch = 0; ch < chunk_channels.size() && ch < merged_channels.size(); ++ch) {
363 merged_channels[ch].insert(merged_channels[ch].end(),
364 chunk_channels[ch].begin(), chunk_channels[ch].end());
369 result.metadata = original_input.metadata;
370 result.metadata[
"sort_type"] =
"chunked_merged";
373 result.data = chunks[0];
385 std::vector<std::vector<double>> working_buffer;
399 return data.has_container();
427template <ComputeData InputType = std::vector<Kakshya::DataVariant>>
Core::GlobalInputConfig input
Modern, digital-first universal sorting framework for Maya Flux.
output_type convert_result(std::vector< std::vector< double > > &result_data, DataStructureInfo &metadata)
Convert processed double data back to OutputType using metadata and optional callback.
static auto setup_operation_buffer(T &input, std::vector< std::vector< double > > &working_buffer)
Setup operation buffer from Datum or ComputeData type.
static std::span< double > extract_numeric_data(const T &compute_data)
extract numeric data from single-variant types
static std::tuple< std::vector< std::span< double > >, DataStructureInfo > extract_structured_double(T &compute_data)
Extract structured double data from Datum container or direct ComputeData with automatic container ha...
void set_algorithm(SortingAlgorithm algorithm)
Configure sorting algorithm.
output_type sort_parallel(const input_type &input)
Parallel sorting.
output_type sort_indices_only(const input_type &input)
Generate sort indices only.
InputType sort_data_partial(const input_type &data)
Partial sorting implementation.
output_type sort_chunked(const input_type &data)
Chunked sorting implementation.
output_type sort_partial(const input_type &input)
Partial sorting (top-K elements)
SortingAlgorithm m_algorithm
StandardSorter()
Constructor with default configuration.
InputType sort_data_copy(const input_type &data)
Sort data with copy semantics.
output_type sort_implementation(const input_type &input) override
Main sorting implementation with type dispatch.
output_type sort_in_place(const input_type &input)
In-place sorting (modifies input)
typename base_type::input_type input_type
void set_sorting_parameter(const std::string &name, std::any value) override
Custom parameter handling.
std::any get_sorting_parameter(const std::string &name) const override
StandardSorter(const StandardSorterConfig &config)
Construct and configure a standard sorter in one step.
bool validate_sorting_input(const input_type &input) const override
Input validation.
output_type sort_copy(const input_type &input)
Copy-based sorting (preserves input)
SortingAlgorithm get_algorithm() const
bool validate_input_type(const input_type &data) const
Validate input type for sorting.
std::string get_sorter_name() const override
Get sorter name.
SortingType get_sorting_type() const override
Get sorting type category.
output_type merge_chunks_to_result(const std::vector< InputType > &chunks, const input_type &original_input, DataStructureInfo info)
Merge chunks back to single result.
void sort_data_in_place(input_type &data)
Sort data in-place.
output_type convert_and_sort(const input_type &input)
Handle type conversion scenarios.
std::vector< InputType > extract_chunked_data(std::vector< std::span< double > > channels, DataStructureInfo info)
typename base_type::output_type output_type
Concrete implementation for standard comparison-based sorting.
void set_sort_keys(const std::vector< SortKey > &keys)
Add multi-key sorting capability.
virtual std::any get_sorting_parameter(const std::string &name) const
SortingStrategy get_strategy() const
virtual void set_sorting_parameter(const std::string &name, std::any value)
Sorting-specific parameter handling (override for custom parameters)
Datum< OutputType > output_type
void set_strategy(SortingStrategy strategy)
Configure sorting strategy.
void set_granularity(SortingGranularity granularity)
Configure output granularity.
void set_parameter(const std::string &name, std::any value) override
Type-safe parameter management with sorting-specific defaults.
void set_direction(SortingDirection direction)
Configure sorting direction.
SortingDirection get_direction() const
Datum< InputType > input_type
Template-flexible sorter base with instance-defined I/O types.
Types that need an associated SignalSourceContainer to extract data.
void sort_span(std::span< double > data, SortingDirection direction, SortingAlgorithm algorithm)
Sort a single span in-place.
void sort_channels(std::vector< std::span< double > > &channels, SortingDirection direction, SortingAlgorithm algorithm)
Sort all channels in-place.
SortingAlgorithm
Available sorting algorithm backends.
SortingDirection
Ascending or descending sort order.
std::vector< std::vector< size_t > > generate_compute_data_indices(const Datum< T > &data, SortingDirection direction)
Generate sort indices for any ComputeData type.
SortingStrategy
Sorting execution strategies.
@ PARTIAL_SORT
Sort only top-K elements.
@ IN_PLACE
Sort data in-place (modifies input)
@ COPY_SORT
Create sorted copy (preserves input)
@ CHUNKED_SORT
Sort in chunks for large datasets.
@ PARALLEL_SORT
Parallel/concurrent sorting.
@ INDEX_ONLY
Generate sort indices only.
SortingType
Categories of sorting operations for discovery and organization.
@ STANDARD
Traditional comparison-based sorting.
void sort_compute_data_inplace(Datum< T > &data, SortingDirection direction, SortingAlgorithm algorithm)
Universal sort function - handles extraction/conversion internally.
T sort_compute_data_extract(const T &data, SortingDirection direction, SortingAlgorithm algorithm)
Universal sort function - returns sorted copy.
SortingGranularity
Output granularity control for sorting results.
@ RAW_DATA
Direct sorted data.
Dimensions, modality, source type, and optional Composite field schema.
std::vector< SortKey > keys
Sort keys and their relative weights.
SortingStrategy strategy
How the input is handled during sorting.
std::map< std::string, std::any > parameters
Additional named parameters applied last.
SortingGranularity granularity
Level at which values are sorted.
SortingAlgorithm algorithm
Sorting algorithm to use.
SortingDirection direction
Order of the sorted result.
size_t chunk_size
Number of elements per chunk for chunked sorting.
Initial settings for standard sorting.