Task Description: Implement the Histogram and LinearHistogram Classes
You need to implement the Histogram and LinearHistogram classes to fulfill the requirements outlined in the provided test code. The goal is to ensure that all test cases in the HistogramTest class pass successfully.
Specific Requirements:
Histogram Class:
Implement a constructor Histogram(int minimum, int maximum, int bucket_count, int flags) that initializes a histogram with a specified range and bucket count.
Implement a static method FactoryGet(const std::string& name, int minimum, int maximum, int bucket_count, int flags) which manages instances of histograms based on their parameters.
Provide a method Add(int sample) to add a sample to the histogram. This method should handle out-of-bounds samples by placing them in appropriate underflow or overflow buckets.
Implement a method SnapshotSample(SampleSet* sample) that captures the current state of the histogram’s data into the provided SampleSet.
Include a method int ranges(int index) that returns the range value for a given histogram bucket index.
Create an attribute bucket_count() that returns the number of buckets in the histogram.
LinearHistogram Class:
Inherit from the Histogram class and implement its constructor similarly, but ensure it manages bucket ranges as linear increments when initialized.
Ensure that when this class is requested via FactoryGet, it correctly creates and initializes an instance of a linear histogram.
SampleSet Structure:
Define a SampleSet structure within the Histogram class that stores counts of samples in each bucket and provides methods for accessing these counts, specifically int counts(int index).
StatisticsRecorder Class:
Implement a StatisticsRecorder class that registers histograms created through FactoryGet. This should be able to return a list of currently registered histograms when GetHistograms(Histograms* histograms) is called.
Implementation Location:
Place all implementation code in the /app/ directory, maintaining file organization as follows:
Create histogram.h for declarations.
Create histogram.cc for implementations.
Ensure the implementation adheres to the behaviors expected by the tests without modifying the provided test code.