docs: static final byte[] toCouponByteArray(final AbstractCoupons impl, final boolean dstCompact) {
      final int srcCouponCount = impl.getCouponCount();
      final int srcLgCouponArrInts = impl.getLgCouponArrInts();
      final int srcCouponArrInts = 1 << srcLgCouponArrInts;
      final byte[] byteArrOut;
      final boolean list = impl.getCurMode() == CurMode.LIST;
      //prepare switch
      final int sw = (impl.isMemory() ? 0 : 4) | (impl.isCompact() ? 0 : 2) | (dstCompact ? 0 : 1);
      switch (sw) {
        case 0: { //Src Memory, Src Compact, Dst Compact
          final Memory srcMem = impl.getMemory();
          final int bytesOut = impl.getMemDataStart() + (srcCouponCount << 2);
          byteArrOut = new byte[bytesOut];
          srcMem.getByteArray(0, byteArrOut, 0, bytesOut);
          break;
        }
        case 1: { //Src Memory, Src Compact, Dst Updatable
          final int dataStart = impl.getMemDataStart();
          final int bytesOut = dataStart + (srcCouponArrInts << 2);
          byteArrOut = new byte[bytesOut];
          final WritableMemory memOut = WritableMemory.wrap(byteArrOut);
          copyCommonListAndSet(impl, memOut);
          insertCompactFlag(memOut, dstCompact);
  
          final int[] tgtCouponIntArr = new int[srcCouponArrInts];
          final PairIterator itr = impl.iterator();
          while (itr.nextValid()) {
            final int pair = itr.getPair();
            final int idx = find(tgtCouponIntArr, srcLgCouponArrInts, pair);
            if (idx < 0) { //found EMPTY
              tgtCouponIntArr[~idx] = pair; //insert
              continue;
            }
            throw new SketchesStateException("Error: found duplicate.");
          }
          memOut.putIntArray(dataStart, tgtCouponIntArr, 0, srcCouponArrInts);
  
          if (list) {
            insertListCount(memOut, srcCouponCount);
          } else {
            insertHashSetCount(memOut, srcCouponCount);
          }
          break;
        }
        case 2: { //Src Memory, Src Updatable, Dst Compact
          final int dataStart = impl.getMemDataStart();
          final int bytesOut = dataStart + (srcCouponCount << 2);
          byteArrOut = new byte[bytesOut];
          final WritableMemory memOut = WritableMemory.wrap(byteArrOut);
          copyCommonListAndSet(impl, memOut);
          insertCompactFlag(memOut, dstCompact);
  
          final PairIterator itr = impl.iterator();
          int cnt = 0;
          while (itr.nextValid()) {
            insertInt(memOut, dataStart + (cnt++ << 2), itr.getPair());
          }
          if (list) {
            insertListCount(memOut, srcCouponCount);
          } else {
            insertHashSetCount(memOut, srcCouponCount);
          }
          break;
        }
        case 3: { //Src Memory, Src Updatable, Dst Updatable
          final Memory srcMem = impl.getMemory();
          final int bytesOut = impl.getMemDataStart() + (srcCouponArrInts << 2);
          byteArrOut = new byte[bytesOut];
          srcMem.getByteArray(0, byteArrOut, 0, bytesOut);
          break;
        }
        case 6: { //Src Heap, Src Updatable, Dst Compact
          final int dataStart = impl.getMemDataStart();
          final int bytesOut = dataStart + (srcCouponCount << 2);
          byteArrOut = new byte[bytesOut];
          final WritableMemory memOut = WritableMemory.wrap(byteArrOut);
          copyCommonListAndSet(impl, memOut);
          insertCompactFlag(memOut, dstCompact);
  
          final PairIterator itr = impl.iterator();
          int cnt = 0;
          while (itr.nextValid()) {
            insertInt(memOut, dataStart + (cnt++ << 2), itr.getPair());
          }
          if (list) {
            insertListCount(memOut, srcCouponCount);
          } else {
            insertHashSetCount(memOut, srcCouponCount);
          }
          break;
        }
        case 7: { //Src Heap, Src Updatable, Dst Updatable
          final int dataStart = impl.getMemDataStart();
          final int bytesOut = dataStart + (srcCouponArrInts << 2);
          byteArrOut = new byte[bytesOut];
          final WritableMemory memOut = WritableMemory.wrap(byteArrOut);
          copyCommonListAndSet(impl, memOut);
  
          memOut.putIntArray(dataStart, impl.getCouponIntArr(), 0, srcCouponArrInts);
          if (list) {
            insertListCount(memOut, srcCouponCount);
          } else {
            insertHashSetCount(memOut, srcCouponCount);
          }
          break;
        }
        default: throw new SketchesStateException("Corruption, should not happen: " + sw);
      }
      return byteArrOut;
    }