| 67 | } |
| 68 | |
| 69 | void MovingAverage::AddValue(double v) { |
| 70 | if (count_ < window_) { |
| 71 | // This is the warmup phase. We don't have a full window's worth of data. |
| 72 | head_ = count_; |
| 73 | data_[count_++] = v; |
| 74 | } else { |
| 75 | if (window_ == ++head_) { |
| 76 | head_ = 0; |
| 77 | } |
| 78 | // Toss the oldest element |
| 79 | sum_ -= data_[head_]; |
| 80 | // Add the newest element |
| 81 | data_[head_] = v; |
| 82 | } |
| 83 | sum_ += v; |
| 84 | } |
| 85 | |
| 86 | static char hex_char[] = "0123456789abcdef"; |
| 87 |