MetricAggregateReplace
The MetricAggregateReplace
type describes a function that can be used to optimize a custom MetricAggregate
by providing a shortcut for when a single value in the input values is replaced with another.
(
metric: Metric,
add: number,
remove: number,
length: number,
): Metric | undefined
Type | Description | |
---|---|---|
metric | Metric | The current value of the |
add | number | The number being added to the |
remove | number | The number being removed from the |
length | number | The length of the array of numbers in the |
returns | Metric | undefined | The new value of the |
Some aggregation functions do not need to recalculate the aggregation of the whole set when one value changes. For example, when replacing a number in a series, the new sum of the series is the previous sum, plus the new value, minus the old value.
If it is not possible to shortcut the aggregation based on just one value changing, return undefined
and the Metric
will be completely recalculated.
When possible, if you are providing a custom MetricAggregate
, seek an implementation of an MetricAggregateReplace
function that can reduce the complexity cost of changing the input data set in place. See the setMetricDefinition
method for more examples.
Since
v1.0.0