histogram.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2016 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. #ifndef MODULES_VIDEO_CODING_HISTOGRAM_H_
  11. #define MODULES_VIDEO_CODING_HISTOGRAM_H_
  12. #include <cstddef>
  13. #include <vector>
  14. namespace webrtc {
  15. namespace video_coding {
  16. class Histogram {
  17. public:
  18. // A discrete histogram where every bucket with range [0, num_buckets).
  19. // Values greater or equal to num_buckets will be placed in the last bucket.
  20. Histogram(size_t num_buckets, size_t max_num_values);
  21. // Add a value to the histogram. If there already is max_num_values in the
  22. // histogram then the oldest value will be replaced with the new value.
  23. void Add(size_t value);
  24. // Calculates how many buckets have to be summed in order to accumulate at
  25. // least the given probability.
  26. size_t InverseCdf(float probability) const;
  27. // How many values that make up this histogram.
  28. size_t NumValues() const;
  29. private:
  30. // A circular buffer that holds the values that make up the histogram.
  31. std::vector<size_t> values_;
  32. std::vector<size_t> buckets_;
  33. size_t index_;
  34. };
  35. } // namespace video_coding
  36. } // namespace webrtc
  37. #endif // MODULES_VIDEO_CODING_HISTOGRAM_H_