docs: protected double assignToNearestCluster(DBIDArrayIter miter, double[] dsum, List<? extends ModifiableDBIDs> clusters, DistanceQuery<V> distQ) {
      double cost = 0;
      double[] dists = new double[k];
      for(DBIDIter iditer = distQ.getRelation().iterDBIDs(); iditer.valid(); iditer.advance()) {
        // Find current cluster assignment. Ugly, but is it worth int[n]?
        final int current = currentCluster(clusters, iditer);
        int minindex = -1;
        double mindist = Double.POSITIVE_INFINITY;
        if(current >= 0) {
          // Always prefer current assignment on ties, for convergence.
          minindex = current;
          mindist = dists[current] = distQ.distance(iditer, miter.seek(current));
        }
        for(miter.seek(0); miter.valid(); miter.advance()) {
          if(miter.getOffset() == current) {
            continue;
          }
          double d = dists[miter.getOffset()] = distQ.distance(iditer, miter);
          if(d < mindist) {
            minindex = miter.getOffset();
            mindist = d;
          }
        }
        cost += mindist;
        if(minindex == current) {
          continue;
        }
        if(!clusters.get(minindex).add(iditer)) {
          throw new IllegalStateException("Reassigning to the same cluster. " + current + " -> " + minindex);
        }
        dsum[minindex] += mindist;
        // Remove from previous cluster
        if(current >= 0) {
          if(!clusters.get(current).remove(iditer)) {
            throw new IllegalStateException("Removing from the wrong cluster.");
          }
          dsum[current] -= dists[current];
        }
      }
      return cost;
    }