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

Function appendBudgetFillSamples

app/src/Sessions/ReportData.cpp:386–416  ·  view source on GitHub ↗

* @brief Appends evenly-spaced samples until @p indices reaches @p budget. */

Source from the content-addressed store, hash-verified

384 * @brief Appends evenly-spaced samples until @p indices reaches @p budget.
385 */
386static void appendBudgetFillSamples(std::size_t count,
387 std::size_t budget,
388 std::vector<std::size_t>& indices)
389{
390 Q_ASSERT(count >= budget);
391 Q_ASSERT(indices.size() <= budget);
392
393 std::vector<unsigned char> used(count, 0);
394 for (const auto index : indices) {
395 Q_ASSERT(index < count);
396 used[index] = 1;
397 }
398
399 const std::size_t divisor = budget - 1;
400 for (std::size_t i = 0; i < budget && indices.size() < budget; ++i) {
401 const std::size_t index = (i == divisor) ? count - 1 : (i * (count - 1)) / divisor;
402 if (used[index])
403 continue;
404
405 used[index] = 1;
406 indices.push_back(index);
407 }
408
409 for (std::size_t i = 0; i < count && indices.size() < budget; ++i) {
410 if (used[i])
411 continue;
412
413 used[i] = 1;
414 indices.push_back(i);
415 }
416}
417
418/**
419 * @brief Copies the selected samples into @p series in chronological order.

Callers 1

writeReportSamplesFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected