Index: webrtc/modules/video_coding/percentile_filter.h |
diff --git a/webrtc/modules/video_coding/percentile_filter.h b/webrtc/modules/video_coding/percentile_filter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7712fd9e35f0a3e7fefd5d90857a5df74e78b1c |
--- /dev/null |
+++ b/webrtc/modules/video_coding/percentile_filter.h |
@@ -0,0 +1,52 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_MODULES_VIDEO_CODING_PERCENTILE_FILTER_H_ |
+#define WEBRTC_MODULES_VIDEO_CODING_PERCENTILE_FILTER_H_ |
+ |
+#include <stdint.h> |
+ |
+#include <set> |
+ |
+namespace webrtc { |
+ |
+// Class to efficiently get the percentile value from a group of observations. |
+// The percentile is the value below which a given percentage of the |
+// observations fall. |
+class PercentileFilter { |
+ public: |
+ // Construct filter. |percentile| should be between 0 and 1. |
+ explicit PercentileFilter(float percentile); |
+ |
+ // Insert one observation. The complexity of this operation is logarithmic in |
+ // the size of the container. |
+ void Insert(const int64_t& value); |
+ // Remove one observation. The complexity of this operation is logarithmic in |
+ // the size of the container. |
+ void Erase(const int64_t& value); |
+ // Get the percentile value. The complexity of this operation is constant. |
+ int64_t GetPercentileValue() const; |
+ // Remove all observations. |
+ void Clear(); |
+ |
+ private: |
+ // Update iterator and index to point at target percentile value. |
+ void UpdatePercentileIterator(); |
+ |
+ const float percentile_; |
+ std::multiset<int64_t> set_; |
+ // Maintain iterator and index of current target percentile value. |
+ std::multiset<int64_t>::iterator percentile_it_; |
+ int64_t percentile_index_; |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_VIDEO_CODING_PERCENTILE_FILTER_H_ |