tlx
Toggle main menu visibility
Loading...
Searching...
No Matches
aggregate_min_max.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/math/aggregate_min_max.hpp
3
*
4
* Part of tlx - http://panthema.net/tlx
5
*
6
* Copyright (C) 2015-2019 Timo Bingmann <tb@panthema.net>
7
*
8
* All rights reserved. Published under the Boost Software License, Version 1.0
9
******************************************************************************/
10
11
#ifndef TLX_MATH_AGGREGATE_MIN_MAX_HEADER
12
#define TLX_MATH_AGGREGATE_MIN_MAX_HEADER
13
14
#include <algorithm>
15
#include <limits>
16
17
namespace
tlx
{
18
19
//! \addtogroup tlx_math
20
//! \{
21
22
/*!
23
* Calculate running aggregate statistics: feed it with values, and it will keep
24
* the minimum and the maximum values.
25
*/
26
template
<
typename
Type_>
27
class
AggregateMinMax
28
{
29
public
:
30
using
Type
= Type_;
31
32
//! default constructor
33
AggregateMinMax
() =
default
;
34
35
//! initializing constructor
36
AggregateMinMax
(
const
Type
&
min
,
const
Type
&
max
) noexcept
37
:
min_
(
min
),
max_
(
max
) { }
38
39
//! add a value to the running aggregation
40
AggregateMinMax
&
add
(
const
Type
& value)
noexcept
{
41
min_
= std::min(
min_
, value);
42
max_
= std::max(
max_
, value);
43
return
*
this
;
44
}
45
46
//! return minimum over all values aggregated
47
const
Type
&
min
() const noexcept {
return
min_
; }
48
49
//! return maximum over all values aggregated
50
const
Type
&
max
() const noexcept {
return
max_
; }
51
52
//! return maximum - minimum over all values aggregated
53
Type
span
() const noexcept {
return
max_
-
min_
; }
54
55
//! change currently aggregated minimum
56
void
set_min
(
const
Type
& v)
noexcept
{
min_
= v; }
57
58
//! change currently aggregated minimum
59
void
set_max
(
const
Type
& v)
noexcept
{
max_
= v; }
60
61
//! operator + to combine two AggregateMinMax<>
62
AggregateMinMax
operator +
(
const
AggregateMinMax
& a)
const
noexcept
{
63
return
AggregateMinMax
(
64
// min, max
65
std::min(
min_
, a.min_), std::max(
max_
, a.max_));
66
}
67
68
//! operator += to combine two AggregateMinMax<>
69
AggregateMinMax
&
operator +=
(
const
AggregateMinMax
& a)
noexcept
{
70
min_
= std::min(
min_
, a.min_);
71
max_
= std::max(
max_
, a.max_);
72
return
*
this
;
73
}
74
75
//! serialization method for cereal.
76
template
<
typename
Archive>
77
void
serialize
(Archive& archive) {
78
archive(
min_
,
max_
);
79
}
80
81
private
:
82
//! minimum value
83
Type
min_
= std::numeric_limits<Type>::max();
84
85
//! maximum value
86
Type
max_
= std::numeric_limits<Type>::lowest();
87
};
88
89
//! \}
90
91
}
// namespace tlx
92
93
#endif
// !TLX_MATH_AGGREGATE_MIN_MAX_HEADER
94
95
/******************************************************************************/
tlx::AggregateMinMax::operator+
AggregateMinMax operator+(const AggregateMinMax &a) const noexcept
operator + to combine two AggregateMinMax<>
Definition
aggregate_min_max.hpp:62
tlx::AggregateMinMax::Type
Type_ Type
Definition
aggregate_min_max.hpp:30
tlx::AggregateMinMax::AggregateMinMax
AggregateMinMax(const Type &min, const Type &max) noexcept
initializing constructor
Definition
aggregate_min_max.hpp:36
tlx::AggregateMinMax::min
const Type & min() const noexcept
return minimum over all values aggregated
Definition
aggregate_min_max.hpp:47
tlx::AggregateMinMax::AggregateMinMax
AggregateMinMax()=default
default constructor
tlx::AggregateMinMax::add
AggregateMinMax & add(const Type &value) noexcept
add a value to the running aggregation
Definition
aggregate_min_max.hpp:40
tlx::AggregateMinMax::serialize
void serialize(Archive &archive)
serialization method for cereal.
Definition
aggregate_min_max.hpp:77
tlx::AggregateMinMax::span
Type span() const noexcept
return maximum - minimum over all values aggregated
Definition
aggregate_min_max.hpp:53
tlx::AggregateMinMax::operator+=
AggregateMinMax & operator+=(const AggregateMinMax &a) noexcept
operator += to combine two AggregateMinMax<>
Definition
aggregate_min_max.hpp:69
tlx::AggregateMinMax::max
const Type & max() const noexcept
return maximum over all values aggregated
Definition
aggregate_min_max.hpp:50
tlx::AggregateMinMax::min_
Type min_
minimum value
Definition
aggregate_min_max.hpp:83
tlx::AggregateMinMax::max_
Type max_
maximum value
Definition
aggregate_min_max.hpp:86
tlx::AggregateMinMax::set_max
void set_max(const Type &v) noexcept
change currently aggregated minimum
Definition
aggregate_min_max.hpp:59
tlx::AggregateMinMax::set_min
void set_min(const Type &v) noexcept
change currently aggregated minimum
Definition
aggregate_min_max.hpp:56
tlx
Definition
exclusive_scan.hpp:17
tlx
math
aggregate_min_max.hpp
Generated on
for tlx by
1.17.0