summaryrefslogtreecommitdiff
path: root/chromium/net/nqe/weighted_observation.h
blob: 334039fa90a4c3baf16431561e494034a95fead9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_NQE_WEIGHTED_OBSERVATION_H_
#define NET_NQE_WEIGHTED_OBSERVATION_H_

#include <vector>

#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "net/base/net_export.h"
#include "net/nqe/network_quality_observation_source.h"

namespace net {

namespace nqe {

namespace internal {

// Holds an observation and its weight.
template <typename ValueType>
struct NET_EXPORT_PRIVATE WeightedObservation {
  WeightedObservation(ValueType value, double weight)
      : value(value), weight(weight) {}
  WeightedObservation(const WeightedObservation& other)
      : WeightedObservation(other.value, other.weight) {}

  WeightedObservation& operator=(const WeightedObservation& other) {
    value = other.value;
    weight = other.weight;
    return *this;
  }

  // Required for sorting the samples in the ascending order of values.
  bool operator<(const WeightedObservation& other) const {
    return (value < other.value);
  }

  // Value of the sample.
  ValueType value;

  // Weight of the sample. This is computed based on how much time has passed
  // since the sample was taken.
  double weight;
};

}  // namespace internal

}  // namespace nqe

}  // namespace net

#endif  // NET_NQE_WEIGHTED_OBSERVATION_H_