Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #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.
| |
| 6 #define NET_BASE_QUANTILE_ESTIMATOR_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "net/base/net_export.h" | |
| 11 | |
| 12 namespace net { | |
| 13 | |
| 14 // This class estimates statistical quantiles (e.g. 10%l, 50%l) for | |
| 15 // distributions presented in stream form. These estimates adjust | |
| 16 // automatically when the stream distribution changes. | |
| 17 class NET_EXPORT QuantileEstimator { | |
| 18 public: | |
| 19 using RandomNumberCallback = base::Callback<int(void)>; | |
| 20 | |
| 21 // |quantile| is a number between 0 and 100 indicating what quantile | |
| 22 // should be estimated (e.g. 50 would be a median estimate). | |
| 23 // |initial_estimate| is the value the class is seeded with; in other | |
| 24 // words, if AddSample() is never called, | |
| 25 // |CurrentEstimate() == initial_estimate|. | |
| 26 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
| |
| 27 | |
| 28 ~QuantileEstimator(); | |
| 29 | |
| 30 int current_estimate() const { return current_estimate_; } | |
| 31 void AddSample(int sample); | |
| 32 | |
| 33 // 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.
| |
| 34 // in the range [0,99] on each call. Used so that tests can | |
| 35 // rely on reproducible behavior. | |
| 36 void SetRandomNumberGeneratorForTesting( | |
| 37 RandomNumberCallback generator_callback); | |
| 38 | |
| 39 private: | |
| 40 const int quantile_; | |
| 41 | |
| 42 bool sign_positive_; | |
| 43 int current_estimate_; | |
| 44 int current_step_; | |
| 45 | |
| 46 RandomNumberCallback generator_callback_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(QuantileEstimator); | |
| 49 }; | |
| 50 | |
| 51 } // namespace net | |
| 52 | |
| 53 #endif // NET_BASE_QUANTILE_ESTIMATOR_ | |
| OLD | NEW |