docs: @SuppressWarnings("unchecked")
    private static <T> T[] combinedBufferToItemsArray(final ItemsSketch<T> sketch,
        final boolean ordered) {
      final int extra = 2; // extra space for min and max values
      final int outArrCap = sketch.getRetainedItems();
      final T minValue = sketch.getMinValue();
      final T[] outArr = (T[]) Array.newInstance(minValue.getClass(), outArrCap + extra);
  
      //Load min, max
      outArr[0] = minValue;
      outArr[1] = sketch.getMaxValue();
      final int baseBufferCount = sketch.getBaseBufferCount();
      final Object[] combinedBuffer = sketch.getCombinedBuffer();
  
      //Load base buffer
      System.arraycopy(combinedBuffer, 0, outArr, extra, baseBufferCount);
  
      //Load levels
      long bitPattern = sketch.getBitPattern();
      if (bitPattern > 0) {
        final int k = sketch.getK();
        int index = extra + baseBufferCount;
        for (int level = 0; bitPattern != 0L; level++, bitPattern >>>= 1) {
          if ((bitPattern & 1L) > 0L) {
            System.arraycopy(combinedBuffer, (2 + level) * k, outArr, index, k);
            index += k;
          }
        }
      }
      if (ordered) {
        Arrays.sort(outArr, extra, baseBufferCount + extra, sketch.getComparator());
      }
      return outArr;
    }