| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_coding/histogram.h" | 11 #include "webrtc/modules/video_coding/histogram.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "webrtc/base/mod_ops.h" | 15 #include "webrtc/base/mod_ops.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 namespace video_coding { | 18 namespace video_coding { |
| 19 Histogram::Histogram(size_t num_buckets, size_t max_num_values) { | 19 Histogram::Histogram(size_t num_buckets, size_t max_num_values) { |
| 20 RTC_DCHECK_GT(num_buckets, 0u); | 20 RTC_DCHECK_GT(num_buckets, 0u); |
| 21 RTC_DCHECK_GT(max_num_values, 0u); | 21 RTC_DCHECK_GT(max_num_values, 0u); |
| 22 buckets_.resize(num_buckets); | 22 buckets_.resize(num_buckets); |
| 23 values_.reserve(max_num_values); | 23 values_.reserve(max_num_values); |
| 24 index_ = 0; | 24 index_ = 0; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void Histogram::Add(size_t value) { | 27 void Histogram::Add(size_t value) { |
| 28 RTC_DCHECK_GE(value, 0u); | |
| 29 value = std::min<size_t>(value, buckets_.size() - 1); | 28 value = std::min<size_t>(value, buckets_.size() - 1); |
| 30 if (index_ < values_.size()) { | 29 if (index_ < values_.size()) { |
| 31 --buckets_[values_[index_]]; | 30 --buckets_[values_[index_]]; |
| 32 RTC_DCHECK_LT(values_[index_], buckets_.size()); | 31 RTC_DCHECK_LT(values_[index_], buckets_.size()); |
| 33 values_[index_] = value; | 32 values_[index_] = value; |
| 34 } else { | 33 } else { |
| 35 values_.emplace_back(value); | 34 values_.emplace_back(value); |
| 36 } | 35 } |
| 37 | 36 |
| 38 ++buckets_[value]; | 37 ++buckets_[value]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 } | 52 } |
| 54 return bucket; | 53 return bucket; |
| 55 } | 54 } |
| 56 | 55 |
| 57 size_t Histogram::NumValues() const { | 56 size_t Histogram::NumValues() const { |
| 58 return values_.size(); | 57 return values_.size(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 } // namespace video_coding | 60 } // namespace video_coding |
| 62 } // namespace webrtc | 61 } // namespace webrtc |
| OLD | NEW |