MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create_multi_key_comparator()

template<typename T >
auto MayaFlux::Yantra::create_multi_key_comparator ( const std::vector< SortKey > &  keys)

Creates a multi-key comparator for complex sorting.

Template Parameters
TData type being sorted
Parameters
keysVector of sort keys with extractors and weights
Returns
Lambda comparator that applies all keys in order

Definition at line 152 of file SortingHelper.hpp.

153{
154 return [keys](const T& a, const T& b) -> bool {
155 for (const auto& key : keys) {
156 try {
157 double val_a = key.extractor(std::any(a));
158 double val_b = key.extractor(std::any(b));
159
160 if (key.normalize) {
161 val_a = std::tanh(val_a);
162 val_b = std::tanh(val_b);
163 }
164
165 double weighted_diff = key.weight * (val_a - val_b);
166 if (std::abs(weighted_diff) > 1e-9) {
167 return key.direction == SortingDirection::ASCENDING ? weighted_diff < 0 : weighted_diff > 0;
168 }
169 } catch (...) {
170 continue;
171 }
172 }
173 return false;
174 };
175}
size_t a
size_t b

References a, and b.