Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: webrtc/base/analytics/percentile_filter.h

Issue 2512693002: Implement Theil-Sen's method for fitting a line to noisy data (used in bandwidth estimation). (Closed)
Patch Set: Unit test for return value of PercentileFilter::Erase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/base/analytics/percentile_filter.h
diff --git a/webrtc/base/analytics/percentile_filter.h b/webrtc/base/analytics/percentile_filter.h
index b3c8f8d1775f8df42b22b9a42d802ce454b9c1cb..d6b36aeb51a9ccafe5e18f267405eb96db969fac 100644
--- a/webrtc/base/analytics/percentile_filter.h
+++ b/webrtc/base/analytics/percentile_filter.h
@@ -33,13 +33,18 @@ class PercentileFilter {
// the size of the container.
void Insert(const T& value);
- // Remove one observation. The complexity of this operation is logarithmic in
- // the size of the container.
- void Erase(const T& value);
+ // Remove one observation or return false if |value| doesn't exist in the
+ // container. The complexity of this operation is logarithmic in the size of
+ // the container.
+ bool Erase(const T& value);
// Get the percentile value. The complexity of this operation is constant.
T GetPercentileValue() const;
+ // Remove all observations from the container and reset the state to that of
+ // a newly contructed object.
+ void Clear();
+
private:
// Update iterator and index to point at target percentile value.
void UpdatePercentileIterator();
@@ -76,11 +81,11 @@ void PercentileFilter<T>::Insert(const T& value) {
}
template <typename T>
-void PercentileFilter<T>::Erase(const T& value) {
+bool PercentileFilter<T>::Erase(const T& value) {
typename std::multiset<T>::const_iterator it = set_.lower_bound(value);
// Ignore erase operation if the element is not present in the current set.
if (it == set_.end() || *it != value)
- return;
+ return false;
if (it == percentile_it_) {
// If same iterator, update to the following element. Index is not
// affected.
@@ -92,6 +97,7 @@ void PercentileFilter<T>::Erase(const T& value) {
--percentile_index_;
}
UpdatePercentileIterator();
+ return true;
}
template <typename T>
@@ -108,6 +114,13 @@ T PercentileFilter<T>::GetPercentileValue() const {
return set_.empty() ? 0 : *percentile_it_;
}
+template <typename T>
+void PercentileFilter<T>::Clear() {
+ set_.clear();
+ percentile_index_ = 0;
+ percentile_it_ = set_.begin();
+}
+
} // namespace webrtc
#endif // WEBRTC_BASE_ANALYTICS_PERCENTILE_FILTER_H_

Powered by Google App Engine
This is Rietveld 408576698