blob: ef75de147026c6cc16eb8decc178fc1674dec4f3 [file] [log] [blame]
Zijie He6a63371a2017-11-03 23:06:411// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef REMOTING_BASE_WEIGHTED_SAMPLES_H_
6#define REMOTING_BASE_WEIGHTED_SAMPLES_H_
7
8#include <cstdint>
9
10namespace remoting {
11
12// Aggregates the samples and gives each of them a weight based on its age. This
13// class can help to smooth the input data.
14class WeightedSamples final {
15 public:
16 explicit WeightedSamples(double weight_factor);
17 ~WeightedSamples();
18
19 void Record(double value);
20 double WeightedAverage() const;
21
22 private:
23 const double weight_factor_;
24 double weighted_sum_ = 0;
25 double weight_ = 0;
26};
27
28} // namespace remoting
29#endif // REMOTING_BASE_WEIGHTED_SAMPLES_H_