Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 11 #include <algorithm> | |
| 12 | |
| 13 #include "webrtc/modules/video_coding/distribution.h" | |
|
stefan-webrtc
2016/03/01 08:52:10
this one should be first
philipel
2016/03/01 10:27:05
Done.
| |
| 14 | |
| 15 #include "webrtc/base/mod_ops.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 | |
| 19 Distribution::Distribution(int num_buckets, int max_num_values) { | |
| 20 buckets_.resize(num_buckets); | |
| 21 values_.reserve(max_num_values); | |
| 22 index_ = 0; | |
| 23 } | |
| 24 | |
| 25 void Distribution::AddValue(int value) { | |
| 26 RTC_DCHECK_LE(0, value); | |
| 27 value = std::min<int>(value, buckets_.size() - 1); | |
| 28 if (index_ < values_.size()) { | |
| 29 buckets_[values_[index_]]--; | |
|
stefan-webrtc
2016/03/01 08:52:10
--buckets_...;
philipel
2016/03/01 10:27:05
Done.
| |
| 30 values_[index_] = value; | |
| 31 } else { | |
| 32 values_.emplace_back(value); | |
| 33 } | |
| 34 | |
| 35 buckets_[value]++; | |
|
stefan-webrtc
2016/03/01 08:52:10
++buckets_...;
philipel
2016/03/01 10:27:05
Done.
| |
| 36 index_ = (index_ + 1) % values_.capacity(); | |
| 37 } | |
| 38 | |
| 39 size_t Distribution::InverseCDF(float probability) const { | |
| 40 RTC_DCHECK_LE(1.f, probability); | |
| 41 RTC_DCHECK_GE(0.f, probability); | |
| 42 RTC_DCHECK_LE(0ul, values_.size()); | |
| 43 | |
| 44 size_t bucket = 0; | |
| 45 float accumulated_probability = 0; | |
| 46 while (accumulated_probability < probability && | |
| 47 bucket < buckets_.size()) { | |
|
stefan-webrtc
2016/03/01 08:52:10
git cl format
philipel
2016/03/01 10:27:05
Done.
| |
| 48 accumulated_probability += static_cast<float>(buckets_[bucket])/ | |
| 49 values_.size(); | |
| 50 ++bucket; | |
| 51 } | |
| 52 return bucket; | |
| 53 } | |
| 54 | |
| 55 size_t Distribution::NumValues() const { | |
| 56 return values_.size(); | |
| 57 } | |
| 58 | |
| 59 } // namespace webrtc | |
| OLD | NEW |