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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 max_stale_ = false; | 49 max_stale_ = false; |
50 min_ = T(); | 50 min_ = T(); |
51 min_stale_ = false; | 51 min_stale_ = false; |
52 } | 52 } |
53 | 53 |
54 void AddSample(T sample) { | 54 void AddSample(T sample) { |
55 if (count_ == max_count()) { | 55 if (count_ == max_count()) { |
56 // Remove oldest sample. | 56 // Remove oldest sample. |
57 T sample_to_remove = samples_[next_index_]; | 57 T sample_to_remove = samples_[next_index_]; |
58 sum_ -= sample_to_remove; | 58 sum_ -= sample_to_remove; |
59 sum_2_ -= sample_to_remove * sample_to_remove; | 59 sum_2_ -= static_cast<double>(sample_to_remove) * sample_to_remove; |
60 if (sample_to_remove >= max_) { | 60 if (sample_to_remove >= max_) { |
61 max_stale_ = true; | 61 max_stale_ = true; |
62 } | 62 } |
63 if (sample_to_remove <= min_) { | 63 if (sample_to_remove <= min_) { |
64 min_stale_ = true; | 64 min_stale_ = true; |
65 } | 65 } |
66 } else { | 66 } else { |
67 // Increase count of samples. | 67 // Increase count of samples. |
68 ++count_; | 68 ++count_; |
69 } | 69 } |
70 // Add new sample. | 70 // Add new sample. |
71 samples_[next_index_] = sample; | 71 samples_[next_index_] = sample; |
72 sum_ += sample; | 72 sum_ += sample; |
73 sum_2_ += sample * sample; | 73 sum_2_ += static_cast<double>(sample) * sample; |
74 if (count_ == 1 || sample >= max_) { | 74 if (count_ == 1 || sample >= max_) { |
75 max_ = sample; | 75 max_ = sample; |
76 max_stale_ = false; | 76 max_stale_ = false; |
77 } | 77 } |
78 if (count_ == 1 || sample <= min_) { | 78 if (count_ == 1 || sample <= min_) { |
79 min_ = sample; | 79 min_ = sample; |
80 min_stale_ = false; | 80 min_stale_ = false; |
81 } | 81 } |
82 // Update next_index_. | 82 // Update next_index_. |
83 next_index_ = (next_index_ + 1) % max_count(); | 83 next_index_ = (next_index_ + 1) % max_count(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 mutable T min_; | 164 mutable T min_; |
165 mutable bool min_stale_; | 165 mutable bool min_stale_; |
166 std::vector<T> samples_; | 166 std::vector<T> samples_; |
167 | 167 |
168 RTC_DISALLOW_COPY_AND_ASSIGN(RollingAccumulator); | 168 RTC_DISALLOW_COPY_AND_ASSIGN(RollingAccumulator); |
169 }; | 169 }; |
170 | 170 |
171 } // namespace rtc | 171 } // namespace rtc |
172 | 172 |
173 #endif // WEBRTC_BASE_ROLLINGACCUMULATOR_H_ | 173 #endif // WEBRTC_BASE_ROLLINGACCUMULATOR_H_ |
OLD | NEW |