docs: static void writeUnary(
        final int[] compressedWords,
        final long[] ptrArr,
        final int theValue) {
  
      int nextWordIndex = (int) ptrArr[NEXT_WORD_IDX]; //must be int
      assert (nextWordIndex == ptrArr[NEXT_WORD_IDX]); //catch truncation error
      long bitBuf = ptrArr[BIT_BUF];                   //must be long
      int bufBits = (int) ptrArr[BUF_BITS];            //could be byte
  
      assert (compressedWords != null);
      assert (nextWordIndex >= 0);
      assert (bitBuf >= 0);
      assert ((bufBits >= 0) && (bufBits <= 31));
  
      int remaining = theValue;
  
      while (remaining >= 16) {
        remaining -= 16;
        // Here we output 16 zeros, but we don't need to physically write them into bitbuf
        // because it already contains zeros in that region.
        bufBits += 16; // Record the fact that 16 bits of output have occurred.
        //MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
        if (bufBits >= 32) {
          compressedWords[nextWordIndex++] = (int) bitBuf;
          bitBuf >>>= 32;
          bufBits -= 32;
        }
      }
  
      assert (remaining >= 0) && (remaining <= 15);
  
      final long theUnaryCode = 1L << remaining; //must be a long
      bitBuf |= theUnaryCode << bufBits;
      bufBits += (1 + remaining);
      //MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
      if (bufBits >= 32) {
        compressedWords[nextWordIndex++] = (int) bitBuf;
        bitBuf >>>= 32;
        bufBits -= 32;
      }
  
      ptrArr[NEXT_WORD_IDX] = nextWordIndex;
      assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch sign extension error
      ptrArr[BIT_BUF] = bitBuf;
      ptrArr[BUF_BITS] = bufBits;
    }