FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

append() method from fcf::NTest::HistogramBasic class

void append(TItem a_item, size_t a_count = 1) const

Class: fcf::NTest::HistogramBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Appends a new item (or multiple items) to the histogram, automatically adjusting the range if necessary.

The append method is used to add data points to the histogram. It is highly efficient for real-time data collection.

Key features:

  • Automatic Resizing: If the appended value falls outside the current [min, max] range, the histogram automatically rebuilds its internal bins to accommodate the new range.
  • Batch Updates: You can append multiple occurrences of the same value at once using the a_count argument.
  • Efficiency: When the value is within the existing range, the update is a constant-time operation.

Arguments

TItem a_item
- The value to be added to the histogram.

size_t a_count = 1
- The number of times this value occurs.

Example: Basic Data Collection

Demonstrating how to append single values and batch values to a histogram.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("HistogramDemo", "Basic", "AppendTest") { // Create a histogram for double values with 5 initial bins fcf::NTest::HistogramBasic<double> hist(5); // 1. Append single values hist.append(10.5); hist.append(20.0); // 2. Append multiple occurrences at once (Batch update) hist.append(15.0, 100); // 3. Append a value that triggers a range rebuild (out of current bounds) hist.append(50.0); // Verify results via logging fcf::NTest::log() << "Total items in histogram: " << hist.counter() << std::endl; FCF_TEST(hist.counter() == 103); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "HistogramDemo" -> "Basic" -> "AppendTest" ... > Total items in histogram: 103 [SUCCESS] Test completed successfully (0.000`017`912 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`017`912 sec

The append method is the primary way to populate your histogram during runtime.