Adds AddSamples function to SamplesStatsCounter.

this allows merging two stats counter objects, will be used in a future
CL to merge statistics for multiple video layers.

Bug: webrtc:10365
Change-Id: Iee9c48b68dfd7ba29537c14fc5f4a7c1c333d145
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131942
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Yves Gerey <yvesg@google.com>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27534}
diff --git a/rtc_base/numerics/samples_stats_counter.cc b/rtc_base/numerics/samples_stats_counter.cc
index 4f6c685..134a65d 100644
--- a/rtc_base/numerics/samples_stats_counter.cc
+++ b/rtc_base/numerics/samples_stats_counter.cc
@@ -38,6 +38,16 @@
   sum_squared_ += value * value;
 }
 
+void SamplesStatsCounter::AddSamples(const SamplesStatsCounter& other) {
+  for (double sample : other.samples_)
+    samples_.push_back(sample);
+  sorted_ = false;
+  max_ = std::max(max_, other.max_);
+  min_ = std::min(min_, other.min_);
+  sum_ += other.sum_;
+  sum_squared_ += other.sum_squared_;
+}
+
 double SamplesStatsCounter::GetPercentile(double percentile) {
   RTC_DCHECK(!IsEmpty());
   RTC_CHECK_GE(percentile, 0);
diff --git a/rtc_base/numerics/samples_stats_counter.h b/rtc_base/numerics/samples_stats_counter.h
index a982b2e..05a8c14 100644
--- a/rtc_base/numerics/samples_stats_counter.h
+++ b/rtc_base/numerics/samples_stats_counter.h
@@ -31,6 +31,9 @@
   // Adds sample to the stats in amortized O(1) time.
   void AddSample(double value);
 
+  // Adds samples from another counter.
+  void AddSamples(const SamplesStatsCounter& other);
+
   // Returns if there are any values in O(1) time.
   bool IsEmpty() const { return samples_.empty(); }