Chromium Code Reviews| 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..5b33174dfe1e1d5b3e8075b13e6e617167e3b0e8 |
| --- /dev/null |
| +++ b/net/base/quantile_estimator.h |
| @@ -0,0 +1,53 @@ |
| +// 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_ |
|
Charlie Harrison
2016/09/01 18:17:53
ESTIMATOR_H_
Randy Smith (Not in Mondays)
2016/09/18 19:12:35
Ooops; thank you. Done.
|
| +#define NET_BASE_QUANTILE_ESTIMATOR_ |
| + |
| +#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 |
| +// distributions presented in stream form. These estimates adjust |
| +// automatically when the stream distribution changes. |
| +class NET_EXPORT QuantileEstimator { |
| + public: |
| + using RandomNumberCallback = base::Callback<int(void)>; |
| + |
| + // |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); |
|
Charlie Harrison
2016/09/01 18:17:53
I wonder if there should be justification for this
Randy Smith (Not in Mondays)
2016/09/18 19:12:35
It was mostly because I didn't need it to operate
|
| + |
| + ~QuantileEstimator(); |
| + |
| + int current_estimate() const { return current_estimate_; } |
| + void AddSample(int sample); |
| + |
| + // Specify a callback that will generator a "random" number |
|
Charlie Harrison
2016/09/01 18:17:53
s/generator/generate
Randy Smith (Not in Mondays)
2016/09/18 19:12:35
Done.
|
| + // 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_ |