code: protected void mergeInsert(final int mergeAt, int insertAt, final float v, final long c)
    {
      final long k0 = (bins[mergeAt] & COUNT_BITS);
      final long k1 = (bins[mergeAt + 1] & COUNT_BITS);
      final long sum = k0 + k1;
  
      // merge bin at given position with the next bin and set approximate flag
      positions[mergeAt] = (float) (((double) positions[mergeAt] * k0 + (double) positions[mergeAt + 1] * k1) / sum);
      bins[mergeAt] = sum | APPROX_FLAG_BIT;
  
      final int unusedIndex = mergeAt + 1;
  
      if (insertAt >= 0) {
        // use unused slot to shift array left or right and make space for the new bin to insert
        if (insertAt < unusedIndex) {
          shiftRight(insertAt, unusedIndex);
        } else if (insertAt >= unusedIndex) {
          shiftLeft(unusedIndex, insertAt - 1);
          insertAt--;
        }
        positions[insertAt] = v;
        bins[insertAt] = c;
        count++;
      } else {
        // simple merging of bins, shift everything left and free up the unused bin
        shiftLeft(unusedIndex, binCount - 1);
        binCount--;
      }
    }
docs: Merges the bin in the mergeAt position with the bin in position mergeAt+1
  and simultaneously inserts the given bin (v,c) as a new bin at position insertAt
  
  @param mergeAt  index of the bin to be merged
  @param insertAt index to insert the new bin at
  @param v        bin position
  @param c        bin count