docs: public static ReservoirLongsSketch heapify(final Memory srcMem) {
      Family.RESERVOIR.checkFamilyID(srcMem.getByte(FAMILY_BYTE));
  
      final int numPreLongs = extractPreLongs(srcMem);
      final ResizeFactor rf = ResizeFactor.getRF(extractResizeFactor(srcMem));
      final int serVer = extractSerVer(srcMem);
      final boolean isEmpty = (extractFlags(srcMem) & EMPTY_FLAG_MASK) != 0;
      final long itemsSeen = (isEmpty ? 0 : extractN(srcMem));
      int k = extractK(srcMem);
  
      // Check values
      final boolean preLongsEqMin = (numPreLongs == Family.RESERVOIR.getMinPreLongs());
      final boolean preLongsEqMax = (numPreLongs == Family.RESERVOIR.getMaxPreLongs());
  
      if (!preLongsEqMin & !preLongsEqMax) {
        throw new SketchesArgumentException("Possible corruption: Non-empty sketch with only "
            + Family.RESERVOIR.getMinPreLongs() + "preLongs");
      }
  
      if (serVer != SER_VER) {
        if (serVer == 1) {
          final short encK = extractEncodedReservoirSize(srcMem);
          k = ReservoirSize.decodeValue(encK);
        } else {
          throw new SketchesArgumentException(
                  "Possible Corruption: Ser Ver must be " + SER_VER + ": " + serVer);
        }
      }
  
      if (isEmpty) {
        return new ReservoirLongsSketch(k, rf);
      }
  
      final int preLongBytes = numPreLongs << 3;
      final int numSketchLongs = (int) Math.min(itemsSeen, k);
      int allocatedSize = k; // default to full reservoir
      if (itemsSeen < k) {
        // under-full so determine size to allocate, using ceilingLog2(totalSeen) as minimum
        // casts to int are safe since under-full
        final int ceilingLgK = Util.toLog2(Util.ceilingPowerOf2(k), "heapify");
        final int minLgSize = Util.toLog2(Util.ceilingPowerOf2((int) itemsSeen), "heapify");
        final int initialLgSize = SamplingUtil.startingSubMultiple(ceilingLgK, rf.lg(),
                Math.max(minLgSize, MIN_LG_ARR_LONGS));
  
        allocatedSize = SamplingUtil.getAdjustedSize(k, 1 << initialLgSize);
      }
  
      final long[] data = new long[allocatedSize];
      srcMem.getLongArray(preLongBytes, data, 0, numSketchLongs);
  
      return new ReservoirLongsSketch(data, itemsSeen, rf, k);
    }