| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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 #ifndef WEBRTC_BASE_ROLLINGACCUMULATOR_H_ | 11 #ifndef WEBRTC_BASE_ROLLINGACCUMULATOR_H_ |
| 12 #define WEBRTC_BASE_ROLLINGACCUMULATOR_H_ | 12 #define WEBRTC_BASE_ROLLINGACCUMULATOR_H_ |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
| 18 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
| 19 | 20 |
| 20 namespace rtc { | 21 namespace rtc { |
| 21 | 22 |
| 22 // RollingAccumulator stores and reports statistics | 23 // RollingAccumulator stores and reports statistics |
| 23 // over N most recent samples. | 24 // over N most recent samples. |
| 24 // | 25 // |
| 25 // T is assumed to be an int, long, double or float. | 26 // T is assumed to be an int, long, double or float. |
| 26 template<typename T> | 27 template<typename T> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 91 |
| 91 double ComputeMean() const { | 92 double ComputeMean() const { |
| 92 if (count_ == 0) { | 93 if (count_ == 0) { |
| 93 return 0.0; | 94 return 0.0; |
| 94 } | 95 } |
| 95 return sum_ / count_; | 96 return sum_ / count_; |
| 96 } | 97 } |
| 97 | 98 |
| 98 T ComputeMax() const { | 99 T ComputeMax() const { |
| 99 if (max_stale_) { | 100 if (max_stale_) { |
| 100 ASSERT(count_ > 0 && | 101 RTC_DCHECK(count_ > 0) << |
| 101 "It shouldn't be possible for max_stale_ && count_ == 0"); | 102 "It shouldn't be possible for max_stale_ && count_ == 0"; |
| 102 max_ = samples_[next_index_]; | 103 max_ = samples_[next_index_]; |
| 103 for (size_t i = 1u; i < count_; i++) { | 104 for (size_t i = 1u; i < count_; i++) { |
| 104 max_ = std::max(max_, samples_[(next_index_ + i) % max_count()]); | 105 max_ = std::max(max_, samples_[(next_index_ + i) % max_count()]); |
| 105 } | 106 } |
| 106 max_stale_ = false; | 107 max_stale_ = false; |
| 107 } | 108 } |
| 108 return max_; | 109 return max_; |
| 109 } | 110 } |
| 110 | 111 |
| 111 T ComputeMin() const { | 112 T ComputeMin() const { |
| 112 if (min_stale_) { | 113 if (min_stale_) { |
| 113 ASSERT(count_ > 0 && | 114 RTC_DCHECK(count_ > 0) << |
| 114 "It shouldn't be possible for min_stale_ && count_ == 0"); | 115 "It shouldn't be possible for min_stale_ && count_ == 0"; |
| 115 min_ = samples_[next_index_]; | 116 min_ = samples_[next_index_]; |
| 116 for (size_t i = 1u; i < count_; i++) { | 117 for (size_t i = 1u; i < count_; i++) { |
| 117 min_ = std::min(min_, samples_[(next_index_ + i) % max_count()]); | 118 min_ = std::min(min_, samples_[(next_index_ + i) % max_count()]); |
| 118 } | 119 } |
| 119 min_stale_ = false; | 120 min_stale_ = false; |
| 120 } | 121 } |
| 121 return min_; | 122 return min_; |
| 122 } | 123 } |
| 123 | 124 |
| 124 // O(n) time complexity. | 125 // O(n) time complexity. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 mutable T min_; | 166 mutable T min_; |
| 166 mutable bool min_stale_; | 167 mutable bool min_stale_; |
| 167 std::vector<T> samples_; | 168 std::vector<T> samples_; |
| 168 | 169 |
| 169 RTC_DISALLOW_COPY_AND_ASSIGN(RollingAccumulator); | 170 RTC_DISALLOW_COPY_AND_ASSIGN(RollingAccumulator); |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 } // namespace rtc | 173 } // namespace rtc |
| 173 | 174 |
| 174 #endif // WEBRTC_BASE_ROLLINGACCUMULATOR_H_ | 175 #endif // WEBRTC_BASE_ROLLINGACCUMULATOR_H_ |
| OLD | NEW |