| 422 | } |
| 423 | |
| 424 | inline ReferenceColumn AggregateReferenceColumn(GeneratedColumn const& col) { |
| 425 | std::vector<std::pair<float, double>> pairs; |
| 426 | pairs.reserve(col.values.size()); |
| 427 | for (std::size_t i = 0; i < col.values.size(); ++i) { |
| 428 | if (col.weights[i] == 0.0f) { |
| 429 | continue; |
| 430 | } |
| 431 | pairs.emplace_back(col.values[i], static_cast<double>(col.weights[i])); |
| 432 | } |
| 433 | std::sort(pairs.begin(), pairs.end(), |
| 434 | [](auto const& lhs, auto const& rhs) { return lhs.first < rhs.first; }); |
| 435 | |
| 436 | std::vector<WeightedValue> out; |
| 437 | for (auto const& [value, weight] : pairs) { |
| 438 | if (!out.empty() && out.back().value == value) { |
| 439 | out.back().weight += weight; |
| 440 | } else { |
| 441 | out.push_back({value, weight}); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | ReferenceColumn ref; |
| 446 | ref.values.reserve(out.size()); |
| 447 | ref.prefix_weights.reserve(out.size() + 1); |
| 448 | ref.prefix_weights.push_back(0.0); |
| 449 | for (auto const& v : out) { |
| 450 | ref.values.push_back(v.value); |
| 451 | ref.prefix_weights.push_back(ref.prefix_weights.back() + v.weight); |
| 452 | } |
| 453 | return ref; |
| 454 | } |
| 455 | |
| 456 | inline double TotalWeight(ReferenceColumn const& col) { return col.prefix_weights.back(); } |
| 457 |
no test coverage detected