accumulate method
dynamic
accumulate(
- int accuIndex,
- int weight
)
Implementation
accumulate(int accuIndex, int weight) {
// note: happily accumulating nothing when weight = 0, the caller knows
// the weight and shouldn't have made the call in the first place
var buffer = this.buffer;
int stride = valueSize;
int offset = accuIndex * stride + stride;
var currentWeight = cumulativeWeight;
if (currentWeight == 0) {
// accuN := incoming * weight
for (var i = 0; i != stride; ++i) {
buffer[offset + i] = buffer[i];
}
currentWeight = weight;
} else {
// accuN := accuN + incoming * weight
currentWeight += weight;
var mix = weight / currentWeight;
_mixBufferRegion(buffer, offset, 0, mix, stride);
}
cumulativeWeight = currentWeight;
}