weighted_observation.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2016 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. #ifndef NET_NQE_WEIGHTED_OBSERVATION_H_
  5. #define NET_NQE_WEIGHTED_OBSERVATION_H_
  6. #include "net/base/net_export.h"
  7. namespace net::nqe::internal {
  8. // Holds an observation and its weight.
  9. struct NET_EXPORT_PRIVATE WeightedObservation {
  10. WeightedObservation(int32_t value, double weight)
  11. : value(value), weight(weight) {}
  12. WeightedObservation(const WeightedObservation& other)
  13. : WeightedObservation(other.value, other.weight) {}
  14. WeightedObservation& operator=(const WeightedObservation& other) = default;
  15. // Required for sorting the samples in the ascending order of values.
  16. bool operator<(const WeightedObservation& other) const {
  17. return (value < other.value);
  18. }
  19. // Value of the sample.
  20. int32_t value;
  21. // Weight of the sample. This is computed based on how much time has passed
  22. // since the sample was taken.
  23. double weight;
  24. };
  25. } // namespace net::nqe::internal
  26. #endif // NET_NQE_WEIGHTED_OBSERVATION_H_