103template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
122 [[nodiscard]] std::string
get_name()
const override
124 return get_sorter_name();
132 if (name ==
"strategy") {
133 auto strategy_result = safe_any_cast<SortingStrategy>(value);
134 if (strategy_result) {
135 m_strategy = *strategy_result.value;
138 auto str_result = safe_any_cast<std::string>(value);
140 auto strategy_enum = Reflect::string_to_enum_case_insensitive<SortingStrategy>(*str_result.value);
142 m_strategy = *strategy_enum;
147 if (name ==
"direction") {
148 auto direction_result = safe_any_cast<SortingDirection>(value);
149 if (direction_result) {
150 m_direction = *direction_result.value;
153 auto str_result = safe_any_cast<std::string>(value);
155 auto direction_enum = Reflect::string_to_enum_case_insensitive<SortingDirection>(*str_result.value);
156 if (direction_enum) {
157 m_direction = *direction_enum;
162 if (name ==
"granularity") {
163 auto granularity_result = safe_any_cast<SortingGranularity>(value);
164 if (granularity_result) {
165 m_granularity = *granularity_result.value;
168 auto str_result = safe_any_cast<std::string>(value);
170 auto granularity_enum = Reflect::string_to_enum_case_insensitive<SortingGranularity>(*str_result.value);
171 if (granularity_enum) {
172 m_granularity = *granularity_enum;
177 set_sorting_parameter(name, std::move(value));
180 [[nodiscard]] std::any
get_parameter(
const std::string& name)
const override
182 if (name ==
"strategy") {
185 if (name ==
"direction") {
188 if (name ==
"granularity") {
189 return m_granularity;
191 return get_sorting_parameter(name);
196 auto params = get_all_sorting_parameters();
197 params[
"strategy"] = m_strategy;
198 params[
"direction"] = m_direction;
199 params[
"granularity"] = m_granularity;
210 template <
typename T>
213 auto param = get_sorting_parameter(name);
214 return safe_any_cast_or_default<T>(param, default_value);
239 void set_sort_keys(
const std::vector<SortKey>& keys) { m_sort_keys = keys; }
246 template <
typename T>
249 m_custom_comparator = [comparator](
const std::any&
a,
const std::any&
b) ->
bool {
250 auto val_a_result = safe_any_cast<T>(
a);
251 auto val_b_result = safe_any_cast<T>(
b);
252 if (val_a_result && val_b_result) {
253 return comparator(*val_a_result, *val_b_result);
267 auto raw_result = sort_implementation(input);
268 return apply_granularity_formatting(raw_result);
282 [[nodiscard]]
virtual std::string
get_sorter_name()
const {
return "UniversalSorter"; }
289 m_parameters[name] = std::move(value);
294 auto it = m_parameters.find(name);
295 return (it != m_parameters.end()) ? it->second : std::any {};
319 switch (m_granularity) {
320 case SortingGranularity::RAW_DATA:
323 case SortingGranularity::ATTRIBUTED_INDICES:
324 return add_sorting_metadata(raw_output);
326 case SortingGranularity::ORGANIZED_GROUPS:
327 return organize_into_groups(raw_output);
329 case SortingGranularity::DETAILED_ANALYSIS:
330 return create_sorting_analysis(raw_output);
343 attributed.
metadata[
"sorting_type"] =
static_cast<int>(get_sorting_type());
344 attributed.
metadata[
"sorter_name"] = get_sorter_name();
345 attributed.
metadata[
"strategy"] =
static_cast<int>(m_strategy);
346 attributed.
metadata[
"direction"] =
static_cast<int>(m_direction);
347 attributed.
metadata[
"granularity"] =
static_cast<int>(m_granularity);
357 return add_sorting_metadata(raw_output);
366 auto analysis = add_sorting_metadata(raw_output);
367 analysis.metadata[
"is_analysis"] =
true;
368 analysis.metadata[
"sort_keys_count"] = m_sort_keys.size();
382 if (m_custom_comparator) {
383 return m_custom_comparator(
a,
b);
393 return !m_sort_keys.empty();
401 template <
typename SortingResultType>
404 m_current_sorting = std::forward<SortingResultType>(result);
420template <ComputeData OutputType = std::vector<Kakshya::DataVariant>>
424template <ComputeData OutputType = std::shared_ptr<Kakshya::SignalSourceContainer>>
428template <ComputeData OutputType = Kakshya::Region>
432template <ComputeData OutputType = Kakshya::RegionGroup>
436template <ComputeData OutputType = std::vector<Kakshya::RegionSegment>>
440template <ComputeData InputType = std::vector<Kakshya::DataVariant>>
444template <ComputeData InputType = std::vector<Kakshya::DataVariant>>
448template <
typename T, ComputeData OutputType = std::vector<std::vector<T>>>
452template <ComputeData InputType = std::vector<Kakshya::DataVariant>>
Base interface for all computational operations in the processing pipeline.
void set_custom_comparator(std::function< bool(const T &, const T &)> comparator)
Configure custom comparator for CUSTOM direction.
void set_sort_keys(const std::vector< SortKey > &keys)
Add multi-key sorting capability.
virtual output_type add_sorting_metadata(const output_type &raw_output)
Add sorting metadata to results (override for custom attribution)
virtual output_type organize_into_groups(const output_type &raw_output)
Organize results into hierarchical groups (override for custom grouping)
virtual std::any get_sorting_parameter(const std::string &name) const
virtual ~UniversalSorter()=default
SortingStrategy get_strategy() const
virtual void set_sorting_parameter(const std::string &name, std::any value)
Sorting-specific parameter handling (override for custom parameters)
virtual output_type apply_granularity_formatting(const output_type &raw_output)
Apply granularity-based output formatting.
std::function< bool(const std::any &, const std::any &)> m_custom_comparator
virtual SortingType get_sorting_type() const =0
Gets the sorting type category for this sorter.
virtual bool should_use_multi_key_sorting() const
Apply multi-key sorting if keys are configured.
std::any get_parameter(const std::string &name) const override
Retrieves a parameter's current value.
std::any m_current_sorting
Current sorting operation storage for complex operations.
void set_strategy(SortingStrategy strategy)
Configure sorting strategy.
std::map< std::string, std::any > m_parameters
bool has_custom_comparator() const
Helper to check if custom comparator is available.
T get_parameter_or_default(const std::string &name, const T &default_value) const
Type-safe parameter access with defaults.
void set_granularity(SortingGranularity granularity)
Configure output granularity.
SortingGranularity get_granularity() const
virtual std::string get_sorter_name() const
Get sorter-specific name (derived classes override this)
const std::vector< SortKey > & get_sort_keys() const
virtual output_type create_sorting_analysis(const output_type &raw_output)
Create detailed sorting analysis (override for custom analysis)
void store_current_sorting(SortingResultType &&result) const
virtual std::map< std::string, std::any > get_all_sorting_parameters() const
void set_parameter(const std::string &name, std::any value) override
Type-safe parameter management with sorting-specific defaults.
std::map< std::string, std::any > get_all_parameters() const override
Retrieves all parameters and their values.
void set_direction(SortingDirection direction)
Configure sorting direction.
output_type operation_function(const input_type &input) override
Core operation implementation - called by ComputeOperation interface.
bool apply_custom_comparator(const std::any &a, const std::any &b) const
Apply custom comparator if available.
SortingDirection get_direction() const
virtual bool validate_sorting_input(const input_type &) const
Input validation (override for custom validation logic)
std::vector< SortKey > m_sort_keys
output_type m_current_output
virtual output_type sort_implementation(const input_type &input)=0
Pure virtual sorting implementation - derived classes implement this.
std::string get_name() const override
Gets human-readable name for this sorter.
Template-flexible sorter base with instance-defined I/O types.
SortingDirection
Ascending or descending sort order.
@ TEMPORAL
Time-based patterns, onset detection.
@ CUSTOM
User-defined analysis types.
@ SPATIAL
Multi-dimensional geometric analysis.
@ RECURSIVE
Recursive/nested extraction.
@ PATTERN_BASED
Extract based on pattern recognition.
SortingStrategy
Sorting execution strategies.
@ LAZY_SORT
Lazy evaluation sorting (future: coroutines)
@ 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.
@ CROSS_MODAL
Sort one modality by features of another.
@ STANDARD
Traditional comparison-based sorting.
@ PREDICTIVE
ML/AI-based predictive sorting.
@ ALGORITHMIC
Mathematical/computational sorting algorithms.
@ ORGANIZED_GROUPS
Hierarchically organized results.
SortingGranularity
Output granularity control for sorting results.
@ RAW_DATA
Direct sorted data.
@ DETAILED_ANALYSIS
Sorting analysis with statistics.
@ ATTRIBUTED_INDICES
Sort indices with metadata.
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Input/Output container for computation pipeline data flow with structure preservation.