code: static HeapCompactDoublesSketch createFromUpdateSketch(final UpdateDoublesSketch sketch) {
      final int k = sketch.getK();
      final long n = sketch.getN();
  
      final HeapCompactDoublesSketch hcds = new HeapCompactDoublesSketch(k); // checks k
  
      hcds.n_ = n;
      hcds.bitPattern_ = computeBitPattern(k, n);
      assert hcds.bitPattern_ == sketch.getBitPattern();
  
      hcds.minValue_ = sketch.getMinValue();
      hcds.maxValue_ = sketch.getMaxValue();
      hcds.baseBufferCount_ = computeBaseBufferItems(k, n);
      assert hcds.baseBufferCount_ == sketch.getBaseBufferCount();
  
      //if (sketch.isEmpty()) {
      //  hcds.combinedBuffer_ = null;
      //  return hcds;
      //}
  
      final int retainedItems = computeRetainedItems(k, n);
      final double[] combinedBuffer = new double[retainedItems];
  
      final DoublesSketchAccessor accessor = DoublesSketchAccessor.wrap(sketch);
      assert hcds.baseBufferCount_ == accessor.numItems();
  
      // copy and sort base buffer
      System.arraycopy(accessor.getArray(0, hcds.baseBufferCount_), 0,
              combinedBuffer, 0,
              hcds.baseBufferCount_);
      Arrays.sort(combinedBuffer, 0, hcds.baseBufferCount_);
  
      int combinedBufferOffset = hcds.baseBufferCount_;
      long bitPattern = hcds.bitPattern_;
      for (int lvl = 0; bitPattern > 0; ++lvl, bitPattern >>>= 1) {
        if ((bitPattern & 1L) > 0L) {
          accessor.setLevel(lvl);
          System.arraycopy(accessor.getArray(0, k), 0,
                  combinedBuffer, combinedBufferOffset, k);
          combinedBufferOffset += k;
        }
      }
      hcds.combinedBuffer_ = combinedBuffer;
  
      return hcds;
    }
docs: Converts the given UpdateDoublesSketch to this compact form.
  
  @param sketch the sketch to convert
  @return a HeapCompactDoublesSketch created from an UpdateDoublesSketch