add method

void add(
  1. double x, [
  2. double w = 1
])

Adds a single sample x with optional weight w (default 1).

Implementation

void add(double x, [double w = 1]) {
  if (x.isNaN || x.isInfinite) return;
  if (w <= 0) return;
  _count += w;
  // Insert in sorted order
  final i = _lowerBound(x);
  if (i < _centroids.length && (_centroids[i].mean - x).abs() <= 1e-12) {
    _centroids[i].add(x, w);
  } else {
    _centroids.insert(i, _Centroid(x, w));
  }
  _compress();
}