Qx v0.5.7
Qt Extensions Library
|
The Cumulation template class tracks the sum of multiple key-value components that can be changed independently. More...
#include <qx/core/qx-cumulation.h>
Public Member Functions | |
Cumulation () | |
void | clear () |
QList< K > | components () const |
bool | contains (K component) const |
qsizetype | count () const |
V | decrement (K component) |
void | increase (K component, V amount) |
V | increment (K component) |
void | insert (K component, V value, V scalar=1) |
bool | isEmpty () const |
V | mean () const |
bool | operator!= (const Cumulation &other) const |
bool | operator== (const Cumulation &other) const |
void | reduce (K component, V amount) |
void | remove (K component) |
void | setScalar (K component, V scalar) |
void | setValue (K component, V value) |
V | total () const |
V | value (K component) const |
A cumulation is a collection of key-value pairs (where V is any arithmetic type) with which the sum of all contained values is always known, and any individual value can be added, removed, or updated through its corresponding key.
Additionally, a cumulation can have optional scalars applied to its components in order to differently weight their individual effect on the total.
This is generally useful for keeping a running total, but when a previously added value may need to be revised later, such as when tracking the overall progress of multiple downloads from a server using their individual progress as components.
|
inline |
Creates an empty cumulation with a total of zero.
|
inline |
Removes all keys/values from the cumulation, resulting in a total of zero.
|
inline |
Returns a list containing all the components in the cumulation, in an arbitrary order.
This function creates a new list, in linear time.
|
inline |
Returns true
if the cumulation contains a value associated with the key component; otherwise returns false
.
|
inline |
Returns that number of components that compose the cumulation.
|
inline |
Decrements the value of the given component and returns the new total.
If the cumulation does not contain the specified component it will be added with a value of -1 and a scalar of 1.
|
inline |
Adds amount to the value of component.
If the cumulation does not contain the specified component it will be added with a value of amount and a scalar of 1.
|
inline |
Increments the value of the given component and returns the new total.
If the cumulation does not contain the specified component it will be added with a value of 1 and a scalar of 1.
|
inline |
Inserts a new component with key component, value value, and scalar scalar.
If there is already a component with the same key, that component's value and scalar are replaced with value and scalar respectively.
|
inline |
Returns true
if the cumulation has no components; otherwise, returns false
.
|
inline |
Returns the current mean of the cumulation, which is the sum of all its component values divided the number of components, or zero if the cumulation is empty.
If V is an integral type, the result is rounded to the nearest integer.
|
inline |
Returns true
if this Cumulation and other Cumulation are not the same; otherwise, returns false
.
|
inline |
Returns true
if this Cumulation and other Cumulation are the same; otherwise, returns false
.
|
inline |
Subtracts amount from the value of component.
If the cumulation does not contain the specified component it will be added with a value of -amount and a scalar of 1.
|
inline |
Removes the value associated with the key component from the cumulation, if it exists.
|
inline |
Sets the scalar of component to scalar.
The amount that a component contributes to a cumulation's total is its value multiplied by its scalar.
If the cumulation does not contain the specified component it will be added with a value of 0 and a scalar of scalar.
|
inline |
Sets the value of component to value.
If the cumulation does not contain the specified component it will be added with a value of value and a scalar of 1.
|
inline |
Returns the current total of the cumulation, which is the sum of all its component values.
|
inline |
Returns the value of component, or a default-constructed value if not present.