Chromium Code Reviews| 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..3ef339f2d2a2bf161a4114e1cb0e8bb6e8985dc0 |
| --- /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 int32_t& value); |
| + // Remove one observation. The complexity of this operation is logarithmic in |
| + // the size of the container. |
| + void Erase(const int32_t& value); |
| + // Get the percentile value. The complexity of this operation is constant. |
| + int32_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<int32_t> set_; |
| + // Maintain iterator and index of current target percentile value. |
| + std::multiset<int32_t>::iterator it_; |
|
philipel
2016/03/03 13:34:31
Change it_ to something more descriptive, like per
magjed_webrtc
2016/03/04 14:19:41
Done.
|
| + int64_t index_; |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_VIDEO_CODING_PERCENTILE_FILTER_H_ |