MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / appendBucketSamples

Function appendBucketSamples

app/src/Sessions/ReportData.cpp:347–381  ·  view source on GitHub ↗

* @brief Appends one bucket's representative sample indices to @p indices. */

Source from the content-addressed store, hash-verified

345 * @brief Appends one bucket's representative sample indices to @p indices.
346 */
347static void appendBucketSamples(const DSP::AxisData& y,
348 std::size_t begin,
349 std::size_t end,
350 int target,
351 std::vector<std::size_t>& indices)
352{
353 Q_ASSERT(begin < end);
354 Q_ASSERT(target > 0);
355
356 const std::size_t bucketSize = end - begin;
357 const std::size_t goal = std::min<std::size_t>(bucketSize, static_cast<std::size_t>(target));
358
359 std::size_t minIndex = begin;
360 std::size_t maxIndex = begin;
361 for (std::size_t i = begin + 1; i < end; ++i) {
362 if (y[i] < y[minIndex])
363 minIndex = i;
364
365 if (y[i] > y[maxIndex])
366 maxIndex = i;
367 }
368
369 std::vector<std::size_t> local;
370 local.reserve(goal);
371 appendUniqueIndex(local, begin);
372 appendUniqueIndex(local, minIndex);
373 appendUniqueIndex(local, maxIndex);
374 appendUniqueIndex(local, end - 1);
375
376 for (std::size_t i = begin + 1; i + 1 < end && local.size() < goal; ++i)
377 appendUniqueIndex(local, i);
378
379 std::sort(local.begin(), local.end());
380 indices.insert(indices.end(), local.begin(), local.end());
381}
382
383/**
384 * @brief Appends evenly-spaced samples until @p indices reaches @p budget.

Callers 1

writeReportSamplesFunction · 0.85

Calls 4

appendUniqueIndexFunction · 0.85
sortFunction · 0.85
beginMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected