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

Unified Diff: net/base/quantile_estimator.h

Issue 2130493002: Implement THROTTLED priority semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NetworkStreamThrottler
Patch Set: Incorporated comments and substantially simplified state storage. Created 4 years, 3 months 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: net/base/quantile_estimator.h
diff --git a/net/base/quantile_estimator.h b/net/base/quantile_estimator.h
new file mode 100644
index 0000000000000000000000000000000000000000..3ad008ed1cf631d0ea591e9747f29d70a1392200
--- /dev/null
+++ b/net/base/quantile_estimator.h
@@ -0,0 +1,58 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_QUANTILE_ESTIMATOR_H_
+#define NET_BASE_QUANTILE_ESTIMATOR_H_
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+// This class estimates statistical quantiles (e.g. 10%l, 50%l) for
+// integer distributions presented in stream form. These estimates adjust
+// automatically when the stream distribution changes.
+// TODO(rdsmith): Expand to floating point, when there's a use case for that
mmenke 2016/09/19 15:26:17 Expand what to floating point? The estimate, or t
Randy Smith (Not in Mondays) 2016/09/22 21:52:27 The estimate. Clarified the commetn.
+// that deserves the extra complexity and pitfalls of floating point
+// arithmetic.
+class NET_EXPORT QuantileEstimator {
+ public:
+ using RandomNumberCallback = base::Callback<int(void)>;
+
+ static const int kMedianQuantile = 50;
+
+ // |quantile| is a number between 0 and 100 indicating what quantile
+ // should be estimated (e.g. 50 would be a median estimate).
+ // |initial_estimate| is the value the class is seeded with; in other
+ // words, if AddSample() is never called,
+ // |CurrentEstimate() == initial_estimate|.
+ QuantileEstimator(int quantile, int initial_estimate);
mmenke 2016/09/19 15:26:17 I think this should technically be Percentile, not
Randy Smith (Not in Mondays) 2016/09/22 21:52:27 That sounds right to me. Ok, one large scale name
+
+ ~QuantileEstimator();
+
+ int current_estimate() const { return current_estimate_; }
+ void AddSample(int sample);
+
+ // Specify a callback that will generate a "random" number
+ // in the range [0,99] on each call. Used so that tests can
+ // rely on reproducible behavior.
+ void SetRandomNumberGeneratorForTesting(
+ RandomNumberCallback generator_callback);
+
+ private:
+ const int quantile_;
+
+ bool sign_positive_;
+ int current_estimate_;
+ int current_step_;
+
+ RandomNumberCallback generator_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuantileEstimator);
+};
+
+} // namespace net
+
+#endif // NET_BASE_QUANTILE_ESTIMATOR_H_

Powered by Google App Engine
This is Rietveld 408576698