18template <
typename K,
typename V>
19 requires arithmetic<V>
37 requires std::integral<N>
40 return !mComponents.
isEmpty() ? std::round(
static_cast<double>(mTotal)/mComponents.
count()) : 0;
44 requires std::floating_point<N>
47 return !mComponents.
isEmpty() ? mTotal/mComponents.
count() : 0;
50 void basicInsert(K component, V
value, V scalar)
52 mTotal +=
value * scalar;
53 mComponents[component] =
value;
54 mScalars[component] = scalar;
63 const V& curVal = mComponents[component];
64 const V& curScal = mScalars[component];
67 if(curVal !=
value || curScal != scalar)
68 mTotal -= curVal * curScal;
74 basicInsert(component,
value, scalar);
81 V& curVal = mComponents[component];
84 const V& scalar = mScalars[component];
85 mTotal += (
value * scalar) - (curVal * scalar);
90 basicInsert(component,
value, 1);
97 V& curScalar = mScalars[component];
98 if(scalar != curScalar)
100 const V&
value = mComponents[component];
101 mTotal += (
value * scalar) - (
value * curScalar);
106 basicInsert(component, 0, scalar);
113 mTotal += amount * mScalars[component];
114 mComponents[component] += amount;
117 basicInsert(component, amount, 1);
124 mTotal -= amount * mScalars[component];
125 mComponents[component] -= amount;
128 basicInsert(component, -amount, 1);
135 mTotal += mScalars[component];
136 mComponents[component]++;
139 basicInsert(component, 1, 1);
148 mTotal -= mScalars[component];
149 mComponents[component]--;
152 basicInsert(component, -1, 1);
161 mTotal -= (mComponents[component] * mScalars[component]);
162 mComponents.
remove(component);
163 mScalars.
remove(component);
175 V
value(K component)
const {
return mComponents.
value(component); }
181 V
mean()
const {
return sMean<V>(); }
185 return mComponents == other.mComponents && mScalars == other.mScalars && mTotal == other.mTotal;
The Cumulation template class tracks the sum of multiple key-value components that can be changed ind...
Definition qx-cumulation.h:21
bool isEmpty() const
Definition qx-cumulation.h:180
bool operator!=(const Cumulation &other) const
Definition qx-cumulation.h:188
V decrement(K component)
Definition qx-cumulation.h:144
V increment(K component)
Definition qx-cumulation.h:131
bool contains(K component) const
Definition qx-cumulation.h:174
void reduce(K component, V amount)
Definition qx-cumulation.h:120
void clear()
Definition qx-cumulation.h:167
V mean() const
Definition qx-cumulation.h:181
void setValue(K component, V value)
Definition qx-cumulation.h:77
V total() const
Definition qx-cumulation.h:176
void increase(K component, V amount)
Definition qx-cumulation.h:109
void setScalar(K component, V scalar)
Definition qx-cumulation.h:93
QList< K > components() const
Definition qx-cumulation.h:177
void remove(K component)
Definition qx-cumulation.h:157
qsizetype count() const
Definition qx-cumulation.h:179
bool operator==(const Cumulation &other) const
Definition qx-cumulation.h:183
V value(K component) const
Definition qx-cumulation.h:175
void insert(K component, V value, V scalar=1)
Definition qx-cumulation.h:58
Cumulation()
Definition qx-cumulation.h:30
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
bool contains(const Key &key) const const
qsizetype count() const const
bool isEmpty() const const
QList< Key > keys() const const
bool remove(const Key &key)
T value(const Key &key) const const
The qx-concepts header file provides a library of general purpose concepts as an extension of the sta...