tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

histogram.h (1927B)


      1 /*
      2 *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
     12 #define MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
     13 
     14 #include <string.h>  // Provide access to size_t.
     15 
     16 #include <optional>
     17 #include <vector>
     18 
     19 namespace webrtc {
     20 
     21 class Histogram {
     22 public:
     23  // Creates histogram with capacity `num_buckets` and `forget_factor` in Q15.
     24  Histogram(size_t num_buckets,
     25            int forget_factor,
     26            std::optional<double> start_forget_weight = std::nullopt);
     27 
     28  virtual ~Histogram();
     29 
     30  // Resets the histogram to the default start distribution.
     31  virtual void Reset();
     32 
     33  // Add entry in bucket `index`.
     34  virtual void Add(int index);
     35 
     36  // Calculates the quantile at `probability` (in Q30) of the histogram
     37  // distribution.
     38  virtual int Quantile(int probability);
     39 
     40  // Returns the number of buckets in the histogram.
     41  virtual int NumBuckets() const;
     42 
     43  // Returns the probability for each bucket in Q30.
     44  const std::vector<int>& buckets() const { return buckets_; }
     45 
     46  // Accessors only intended for testing purposes.
     47  int base_forget_factor_for_testing() const { return base_forget_factor_; }
     48  int forget_factor_for_testing() const { return forget_factor_; }
     49  std::optional<double> start_forget_weight_for_testing() const {
     50    return start_forget_weight_;
     51  }
     52 
     53 private:
     54  std::vector<int> buckets_;
     55  int forget_factor_;  // Q15
     56  const int base_forget_factor_;
     57  int add_count_;
     58  const std::optional<double> start_forget_weight_;
     59 };
     60 
     61 }  // namespace webrtc
     62 
     63 #endif  // MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_