111 SortKey(std::string n, std::function<
double(
const std::any&)> e)
113 , extractor(
std::move(e))
130template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
149 [[nodiscard]] std::string
get_name()
const override
151 return get_sorter_name();
159 if (name ==
"strategy") {
160 auto strategy_result = safe_any_cast<SortingStrategy>(value);
161 if (strategy_result) {
162 m_strategy = *strategy_result.value;
165 auto str_result = safe_any_cast<std::string>(value);
167 auto strategy_enum = Utils::string_to_enum_case_insensitive<SortingStrategy>(*str_result.value);
169 m_strategy = *strategy_enum;
174 if (name ==
"direction") {
175 auto direction_result = safe_any_cast<SortingDirection>(value);
176 if (direction_result) {
177 m_direction = *direction_result.value;
180 auto str_result = safe_any_cast<std::string>(value);
182 auto direction_enum = Utils::string_to_enum_case_insensitive<SortingDirection>(*str_result.value);
183 if (direction_enum) {
184 m_direction = *direction_enum;
189 if (name ==
"granularity") {
190 auto granularity_result = safe_any_cast<SortingGranularity>(value);
191 if (granularity_result) {
192 m_granularity = *granularity_result.value;
195 auto str_result = safe_any_cast<std::string>(value);
197 auto granularity_enum = Utils::string_to_enum_case_insensitive<SortingGranularity>(*str_result.value);
198 if (granularity_enum) {
199 m_granularity = *granularity_enum;
204 set_sorting_parameter(name, std::move(value));
207 [[nodiscard]] std::any
get_parameter(
const std::string& name)
const override
209 if (name ==
"strategy") {
212 if (name ==
"direction") {
215 if (name ==
"granularity") {
216 return m_granularity;
218 return get_sorting_parameter(name);
223 auto params = get_all_sorting_parameters();
224 params[
"strategy"] = m_strategy;
225 params[
"direction"] = m_direction;
226 params[
"granularity"] = m_granularity;
237 template <
typename T>
240 auto param = get_sorting_parameter(name);
241 return safe_any_cast_or_default<T>(param, default_value);
266 void set_sort_keys(
const std::vector<SortKey>& keys) { m_sort_keys = keys; }
273 template <
typename T>
276 m_custom_comparator = [comparator](
const std::any& a,
const std::any& b) ->
bool {
277 auto val_a_result = safe_any_cast<T>(a);
278 auto val_b_result = safe_any_cast<T>(b);
279 if (val_a_result && val_b_result) {
280 return comparator(*val_a_result, *val_b_result);
294 auto raw_result = sort_implementation(input);
295 return apply_granularity_formatting(raw_result);
309 [[nodiscard]]
virtual std::string
get_sorter_name()
const {
return "UniversalSorter"; }
316 m_parameters[name] = std::move(value);
321 auto it = m_parameters.find(name);
322 return (it != m_parameters.end()) ? it->second : std::any {};
346 switch (m_granularity) {
347 case SortingGranularity::RAW_DATA:
350 case SortingGranularity::ATTRIBUTED_INDICES:
351 return add_sorting_metadata(raw_output);
353 case SortingGranularity::ORGANIZED_GROUPS:
354 return organize_into_groups(raw_output);
356 case SortingGranularity::DETAILED_ANALYSIS:
357 return create_sorting_analysis(raw_output);
370 attributed.
metadata[
"sorting_type"] =
static_cast<int>(get_sorting_type());
371 attributed.
metadata[
"sorter_name"] = get_sorter_name();
372 attributed.
metadata[
"strategy"] =
static_cast<int>(m_strategy);
373 attributed.
metadata[
"direction"] =
static_cast<int>(m_direction);
374 attributed.
metadata[
"granularity"] =
static_cast<int>(m_granularity);
384 return add_sorting_metadata(raw_output);
393 auto analysis = add_sorting_metadata(raw_output);
394 analysis.metadata[
"is_analysis"] =
true;
395 analysis.metadata[
"sort_keys_count"] = m_sort_keys.size();
409 if (m_custom_comparator) {
410 return m_custom_comparator(a, b);
420 return !m_sort_keys.empty();
428 template <
typename SortingResultType>
431 m_current_sorting = std::forward<SortingResultType>(result);
447template <ComputeData OutputType = std::vector<Kakshya::DataVariant>>
451template <ComputeData OutputType = std::shared_ptr<Kakshya::SignalSourceContainer>>
455template <ComputeData OutputType = Kakshya::Region>
459template <ComputeData OutputType = Kakshya::RegionGroup>
463template <ComputeData OutputType = std::vector<Kakshya::RegionSegment>>
467template <ComputeData InputType = std::vector<Kakshya::DataVariant>>
471template <ComputeData InputType = std::vector<Kakshya::DataVariant>>
475template <
typename T, ComputeData OutputType = std::vector<std::vector<T>>>
479template <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.
@ 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.
@ PREDICTIVE
ML/AI-based predictive sorting.
@ ALGORITHMIC
Mathematical/computational sorting algorithms.
@ ORGANIZED_GROUPS
Hierarchically organized results.
SortingDirection
Basic sort direction for simple comparisons.
@ BIDIRECTIONAL
Sort with both directions (for special algorithms)
@ ASCENDING
Smallest to largest.
@ DESCENDING
Largest to smallest.
@ STANDARD
std::sort with comparator
SortingGranularity
Output granularity control for sorting results.
@ RAW_DATA
Direct sorted data.
@ DETAILED_ANALYSIS
Sorting analysis with statistics.
@ ATTRIBUTED_INDICES
Sort indices with metadata.
void normalize(std::vector< double > &data, double target_peak)
Normalize single-channel data to specified peak level (in-place)
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Input/Output container for computation pipeline data flow with structure preservation.
std::function< double(const std::any &)> extractor
Extract sort value from data.
SortKey(std::string n, std::function< double(const std::any &)> e)
Multi-dimensional sort key specification for complex sorting.