/// <summary>
/// Add the contents of another histogram to this one.
/// </summary>
/// <param name="fromHistogram">The other histogram.</param>
/// <exception cref="System.IndexOutOfRangeException">if values in fromHistogram's are higher than highestTrackableValue.</exception>
public virtual void Add(HistogramBase fromHistogram)
{
if (HighestTrackableValue < fromHistogram.HighestTrackableValue)
{
throw new ArgumentOutOfRangeException(nameof(fromHistogram), $"The other histogram covers a wider range ({fromHistogram.HighestTrackableValue} than this one ({HighestTrackableValue}).");
}
if ((BucketCount == fromHistogram.BucketCount) &&
(SubBucketCount == fromHistogram.SubBucketCount) &&
(_unitMagnitude == fromHistogram._unitMagnitude))
{
// Counts arrays are of the same length and meaning, so we can just iterate and add directly:
for (var i = 0; i < fromHistogram.CountsArrayLength; i++)
{
AddToCountAtIndex(i, fromHistogram.GetCountAtIndex(i));
}
}
else
{
// Arrays are not a direct match, so we can't just stream through and add them.
// Instead, go through the array and add each non-zero value found at it's proper value:
for (var i = 0; i < fromHistogram.CountsArrayLength; i++)
{
var count = fromHistogram.GetCountAtIndex(i);
RecordValueWithCount(fromHistogram.ValueFromIndex(i), count);
}
}
}