append() method from fcf::NTest::HistogramBasic class
Class:
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
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_countargument. - Efficiency: When the value is within the existing range, the update is a constant-time operation.
Arguments
- The value to be added to the histogram.
- 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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.