accumulate method

void accumulate(
  1. int accuIndex,
  2. double weight
)

Accumulate data in accuIndex incoming region into accu[i]. If weight is 0 this does nothing.

Implementation

/// If weight is `0` this does nothing.
void accumulate(int accuIndex, double weight) {
  // note: happily accumulating nothing when weight = 0, the caller knows
  // the weight and shouldn't have made the call in the first place

  final buffer = this.buffer;
  int stride = valueSize;
  int offset = accuIndex * stride + stride;
  double currentWeight = cumulativeWeight;

  if (currentWeight == 0) {
    // accuN := incoming * weight
    for (int i = 0; i != stride; ++i) {
      buffer[offset + i] = buffer[i];
    }
    currentWeight = weight;
  }
  else {
    // accuN := accuN + incoming * weight
    currentWeight += weight;
    final mix = weight / currentWeight;
    _mixBufferRegion(buffer, offset, 0, mix, stride);
  }

  cumulativeWeight = currentWeight;
}