docs: static DirectCompactDoublesSketch createFromUpdateSketch(final UpdateDoublesSketch sketch,
                                                             final WritableMemory dstMem) {
      final long memCap = dstMem.getCapacity();
      final int k = sketch.getK();
      final long n = sketch.getN();
      checkDirectMemCapacity(k, n, memCap);
  
      //initialize dstMem
      dstMem.putLong(0, 0L); //clear pre0
      insertPreLongs(dstMem, 2);
      insertSerVer(dstMem, DoublesSketch.DOUBLES_SER_VER);
      insertFamilyID(dstMem, Family.QUANTILES.getID());
      insertK(dstMem, k);
  
      final int flags = COMPACT_FLAG_MASK | READ_ONLY_FLAG_MASK; // true for all compact sketches
  
      if (sketch.isEmpty()) {
        insertFlags(dstMem, flags | EMPTY_FLAG_MASK);
      } else {
        insertFlags(dstMem, flags);
        insertN(dstMem, n);
        insertMinDouble(dstMem, sketch.getMinValue());
        insertMaxDouble(dstMem, sketch.getMaxValue());
  
        final int bbCount = computeBaseBufferItems(k, n);
  
        final DoublesSketchAccessor inputAccessor = DoublesSketchAccessor.wrap(sketch);
        assert bbCount == inputAccessor.numItems();
  
        long dstMemOffset = COMBINED_BUFFER;
  
        // copy and sort base buffer
        final double[] bbArray = inputAccessor.getArray(0, bbCount);
        Arrays.sort(bbArray);
        dstMem.putDoubleArray(dstMemOffset, bbArray, 0, bbCount);
        dstMemOffset += bbCount << 3;
  
        long bitPattern = computeBitPattern(k, n);
        for (int lvl = 0; bitPattern > 0; ++lvl, bitPattern >>>= 1) {
          if ((bitPattern & 1L) > 0L) {
            inputAccessor.setLevel(lvl);
            dstMem.putDoubleArray(dstMemOffset, inputAccessor.getArray(0, k), 0, k);
            dstMemOffset += k << 3;
          }
        }
      }
  
      final DirectCompactDoublesSketch dcds = new DirectCompactDoublesSketch(k);
      dcds.mem_ = dstMem;
  
      return dcds;
    }