of input values and out[0] has the long to write
975295
public int add(long v, long[] out) {
        //System.out.println("S64.add v=" + v + " " + (1 + inputCount - inputCompressable) + " waiting");
        pending[inputCount++] = v;
        while (inputCompressable <= inputCount) {
            final long nextData = pending[(inputCompressable - 1)];
            //System.out.println("  cycle: data=" + nextData);
            while ((nextData >= maxFitPlus1) && (minBits < NUM_DATA_BITS)) {
                //System.out.println("  cycle maxFitPlus1=" + maxFitPlus1 + " minBits=" + minBits);
                if ((minBits == 7) && (inputCompressable == 8) && (nextData < (maxFitPlus1 << 4))) {
                    break;
                } else if ((minBits == 8) && (inputCompressable == 7) && (nextData < (maxFitPlus1 << 4))) {
                    break;
                } else {
                    //System.out.println("  advance");
                    minBits++;
                    maxFitPlus1 <<= 1;
                    if ((inputCompressable * minBits) > NUM_DATA_BITS) {
                        inputCompressable--;
                        //System.out.println("  hard break");
                        break;
                    }
                }
            }
            inputCompressable++;

            //System.out.println("  minBits=" + minBits + " count=" + (inputCompressable-1) + " inputCount=" + inputCount);

            if ((inputCompressable * minBits) > NUM_DATA_BITS) {
                // Time to compress!
                inputCompressable--;
                //System.out.println("  FLUSH count=" + inputCompressable);

                // nocommit -- it should always be > 0... right??
                assert inputCompressable > 0;

                // Check whether a bigger number of bits can be used:
                while ((inputCompressable * (minBits + 1)) <= NUM_DATA_BITS) {
                    minBits++;
                    //System.out.println("  incr minBits=" + minBits);
                }

        /*
          if (((inputCompressable+1) * minBits) <= NUM_DATA_BITS) {
          // not enough input available for minBits
          minBits++;
          // do not compress all available input
          inputCompressable = NUM_DATA_BITS / minBits;
          }
        */

                // Put compression method in status bits and encode input data
                long s9;
                final int consumed;
                switch (minBits) { // add status bits and later input values
                    case 60:
                        s9 = STATUS_1NUM_60BITS;
                        s9 |= pending[0] << 4;
                        consumed = 1;
                        break;
                    case 30:
                        s9 = STATUS_2NUM_30BITS;
                        // nocommit -- make a single expr instead of |'ing ?
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 34;
                        consumed = 2;
                        break;
                    case 20:
                        s9 = STATUS_3NUM_20BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 24;
                        s9 |= pending[2] << 44;
                        consumed = 3;
                        break;
                    case 15:
                        s9 = STATUS_4NUM_15BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 19;
                        s9 |= pending[2] << 34;
                        s9 |= pending[3] << 49;
                        consumed = 4;
                        break;
                    case 12:
                        s9 = STATUS_5NUM_12BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 16;
                        s9 |= pending[2] << 28;
                        s9 |= pending[3] << 40;
                        s9 |= pending[4] << 52;
                        consumed = 5;
                        break;
                    case 10:
                        s9 = STATUS_6NUM_10BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 14;
                        s9 |= pending[2] << 24;
                        s9 |= pending[3] << 34;
                        s9 |= pending[4] << 44;
                        s9 |= pending[5] << 54;
                        consumed = 6;
                        break;
                    case 8:
                        s9 = STATUS_7NUM_8BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 12;
                        s9 |= pending[2] << 20;
                        s9 |= pending[3] << 28;
                        s9 |= pending[4] << 36;
                        s9 |= pending[5] << 44;
                        s9 |= pending[6] << 52; // 4 more bits
                        consumed = 7;
                        break;
                    case 7:
                        s9 = STATUS_8NUM_7BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 11;
                        s9 |= pending[2] << 18;
                        s9 |= pending[3] << 25;
                        s9 |= pending[4] << 32;
                        s9 |= pending[5] << 39;
                        s9 |= pending[6] << 46;
                        s9 |= pending[7] << 53; // 4 more bits
                        consumed = 8;
                        break;
                    case 6:
                        s9 = STATUS_10NUM_6BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 10;
                        s9 |= pending[2] << 16;
                        s9 |= pending[3] << 22;
                        s9 |= pending[4] << 28;
                        s9 |= pending[5] << 34;
                        s9 |= pending[6] << 40;
                        s9 |= pending[7] << 46;
                        s9 |= pending[8] << 52;
                        s9 |= pending[9] << 58;
                        consumed = 10;
                        break;
                    case 5:
                        s9 = STATUS_12NUM_5BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 9;
                        s9 |= pending[2] << 14;
                        s9 |= pending[3] << 19;
                        s9 |= pending[4] << 24;
                        s9 |= pending[5] << 29;
                        s9 |= pending[6] << 34;
                        s9 |= pending[7] << 39;
                        s9 |= pending[8] << 44;
                        s9 |= pending[9] << 49;
                        s9 |= pending[10] << 54;
                        s9 |= pending[11] << 59;
                        consumed = 12;
                        break;
                    case 4:
                        s9 = STATUS_15NUM_4BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 8;
                        s9 |= pending[2] << 12;
                        s9 |= pending[3] << 16;
                        s9 |= pending[4] << 20;
                        s9 |= pending[5] << 24;
                        s9 |= pending[6] << 28;
                        s9 |= pending[7] << 32;
                        s9 |= pending[8] << 36;
                        s9 |= pending[9] << 40;
                        s9 |= pending[10] << 44;
                        s9 |= pending[11] << 48;
                        s9 |= pending[12] << 52;
                        s9 |= pending[13] << 56;
                        s9 |= pending[14] << 60;
                        consumed = 15;
                        break;
                    case 3:
                        s9 = STATUS_20NUM_3BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 7;
                        s9 |= pending[2] << 10;
                        s9 |= pending[3] << 13;
                        s9 |= pending[4] << 16;
                        s9 |= pending[5] << 19;
                        s9 |= pending[6] << 22;
                        s9 |= pending[7] << 25;
                        s9 |= pending[8] << 28;
                        s9 |= pending[9] << 31;
                        s9 |= pending[10] << 34;
                        s9 |= pending[11] << 37;
                        s9 |= pending[12] << 40;
                        s9 |= pending[13] << 43;
                        s9 |= pending[14] << 46;
                        s9 |= pending[15] << 49;
                        s9 |= pending[16] << 52;
                        s9 |= pending[17] << 55;
                        s9 |= pending[18] << 58;
                        s9 |= pending[19] << 61;
                        consumed = 20;
                        break;
                    case 2:
                        s9 = STATUS_30NUM_2BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 6;
                        s9 |= pending[2] << 8;
                        s9 |= pending[3] << 10;
                        s9 |= pending[4] << 12;
                        s9 |= pending[5] << 14;
                        s9 |= pending[6] << 16;
                        s9 |= pending[7] << 18;
                        s9 |= pending[8] << 20;
                        s9 |= pending[9] << 22;
                        s9 |= pending[10] << 24;
                        s9 |= pending[11] << 26;
                        s9 |= pending[12] << 28;
                        s9 |= pending[13] << 30;
                        s9 |= pending[14] << 32;
                        s9 |= pending[15] << 34;
                        s9 |= pending[16] << 36;
                        s9 |= pending[17] << 38;
                        s9 |= pending[18] << 40;
                        s9 |= pending[19] << 42;
                        s9 |= pending[20] << 44;
                        s9 |= pending[21] << 46;
                        s9 |= pending[22] << 48;
                        s9 |= pending[23] << 50;
                        s9 |= pending[24] << 52;
                        s9 |= pending[25] << 54;
                        s9 |= pending[26] << 56;
                        s9 |= pending[27] << 58;
                        s9 |= pending[28] << 60;
                        s9 |= pending[29] << 62;
                        consumed = 30;
                        break;
                    case 1:
                        s9 = STATUS_60NUM_1BITS;
                        s9 |= pending[0] << 4;
                        s9 |= pending[1] << 5;
                        s9 |= pending[2] << 6;
                        s9 |= pending[3] << 7;
                        s9 |= pending[4] << 8;
                        s9 |= pending[5] << 9;
                        s9 |= pending[6] << 10;
                        s9 |= pending[7] << 11;
                        s9 |= pending[8] << 12;
                        s9 |= pending[9] << 13;
                        s9 |= pending[10] << 14;
                        s9 |= pending[11] << 15;
                        s9 |= pending[12] << 16;
                        s9 |= pending[13] << 17;
                        s9 |= pending[14] << 18;
                        s9 |= pending[15] << 19;
                        s9 |= pending[16] << 20;
                        s9 |= pending[17] << 21;
                        s9 |= pending[18] << 22;
                        s9 |= pending[19] << 23;
                        s9 |= pending[20] << 24;
                        s9 |= pending[21] << 25;
                        s9 |= pending[22] << 26;
                        s9 |= pending[23] << 27;
                        s9 |= pending[24] << 28;
                        s9 |= pending[25] << 29;
                        s9 |= pending[26] << 30;
                        s9 |= pending[27] << 31;
                        s9 |= pending[28] << 32;
                        s9 |= pending[29] << 33;
                        s9 |= pending[30] << 34;
                        s9 |= pending[31] << 35;
                        s9 |= pending[32] << 36;
                        s9 |= pending[33] << 37;
                        s9 |= pending[34] << 38;
                        s9 |= pending[35] << 39;
                        s9 |= pending[36] << 40;
                        s9 |= pending[37] << 41;
                        s9 |= pending[38] << 42;
                        s9 |= pending[39] << 43;
                        s9 |= pending[40] << 44;
                        s9 |= pending[41] << 45;
                        s9 |= pending[42] << 46;
                        s9 |= pending[43] << 47;
                        s9 |= pending[44] << 48;
                        s9 |= pending[45] << 49;
                        s9 |= pending[46] << 50;
                        s9 |= pending[47] << 51;
                        s9 |= pending[48] << 52;
                        s9 |= pending[49] << 53;
                        s9 |= pending[50] << 54;
                        s9 |= pending[51] << 55;
                        s9 |= pending[52] << 56;
                        s9 |= pending[53] << 57;
                        s9 |= pending[54] << 58;
                        s9 |= pending[55] << 59;
                        s9 |= pending[56] << 60;
                        s9 |= pending[57] << 61;
                        s9 |= pending[58] << 62;
                        s9 |= pending[59] << 63;
                        consumed = 60;
                        break;
                    default:
                        assert false;
                        s9 = 0;
                        consumed = 60;
                        //throw new Error("S98b.compressSingle internal error: unknown minBits: " + minBits);
                }

                final int leftover = inputCount - consumed;
                assert leftover >= 0 : "consumed=" + consumed + " vs " + inputCompressable;

        /*
        for(int x=0;x<consumed;x++) {
          System.out.println(""+pending[x]);
        }
        */
        /*
        // like cd burning!  ;)
        {
        int[] test = new int[consumed];
        int ct = decompressSingle(s9, test, 0);
        assert ct == consumed;
        for(int x=0;x<ct;x++) {
        assert test[x] == pending[x];
        }
        }
        */

                //System.out.println("  return consumed=" + consumed);
                reset();

                // save leftovers:
                System.arraycopy(pending, consumed, pending, 0, leftover);
                inputCount = leftover;

                out[0] = s9;
                return consumed;
            }
        }

        return 0;
    }
272834
@Override
    public long convert(int[] input, int inPos) {
        int Y = input[inPos++] & 0xFF;
        int Cb = input[inPos++] & 0xFF;
        int Cr = input[inPos] & 0xFF;

        byte r = (byte) sampleRangeLimitTable[sampleRangeLimitOffset + Y + Cr2R[Cr]];
        byte g = (byte) sampleRangeLimitTable[sampleRangeLimitOffset + Y + ((Cb2G[Cb] + Cr2G[Cr]) >> 16)];

        byte b = (byte) sampleRangeLimitTable[sampleRangeLimitOffset + Y + Cb2B[Cb]];

        return (0xFF000000L | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF));
    }
896857
function encodeInputs(inputs, add_address_to_previous_output_index) {
    //Initialize buffer and offset
    let offset = 0;
    var buffer = Buffer.allocUnsafe(100000);
    //Write number of inputs
    offset += bufferutils.writeVarInt(buffer, inputs.length, offset);

    inputs.forEach((input, index) => {
        //Write reversed hash
        offset += Buffer.from(input.previous_output.hash, 'hex').reverse().copy(buffer, offset);
        //Index
        offset = buffer.writeUInt32LE(input.previous_output.index, offset);
        if (add_address_to_previous_output_index !== undefined) {
            if (index == add_address_to_previous_output_index) {
                let lockregex = /^\[\ ([a-f0-9]+)\ \]\ numequalverify dup\ hash160\ \[ [a-f0-9]+\ \]\ equalverify\ checksig$/gi;
                if (input.previous_output.script && input.previous_output.script.match(lockregex)) {
                    let locktime = lockregex.exec(input.previous_output.script.match(lockregex)[0])[1];
                    offset = writeScriptLockedPayToPubKeyHash(input.previous_output.address, locktime, buffer, offset);
                } else {
                    if (Script.hasAttenuationModel(input.previous_output.script)) {
                        let params = Script.getAttenuationParams(input.previous_output.script);
                        offset = writeAttenuationScript(params.model, (params.hash !== '0000000000000000000000000000000000000000000000000000000000000000') ? params.hash : undefined, (params.index >= 0) ? params.index : undefined, input.previous_output.address, buffer, offset);
                    } else {
                        if (Script.isP2SH(input.previous_output.script)) {
                            let script_buffer = Buffer.from(input.redeem, 'hex');
                            offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
                            offset += script_buffer.copy(buffer, offset);
                        } else {
                            if (input.previous_output.script) {
                                let script_buffer = Script.fromASM(input.previous_output.script).toBuffer()
                                offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
                                offset += script_buffer.copy(buffer, offset);
                            } else {
                                offset = writeScriptPayToPubKeyHash(input.previous_output.address, buffer, offset);
                            }
                        }
                    }
                }
            } else {
                offset = buffer.writeUInt8(0, offset);
            }
        } else {
            //input script
            let script_buffer = encodeInputScript(input.script);
            offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
            offset += script_buffer.copy(buffer, offset);
        }

        offset = buffer.writeUInt32LE(input.sequence, offset);
    });
    return buffer.slice(0, offset);
}
601407
public static int writeShorts(final BitOutput bitOutput, final int lengthSize, final int shortSize,
                                  final short[] value)
            throws IOException {
        if (bitOutput == null) {
            throw new NullPointerException("bitOutput is null");
        }
        requireValidSizeInt(true, lengthSize);
        requireValidSizeShort(false, shortSize);
        if (value == null) {
            throw new NullPointerException("value is null");
        }
        final int length = value.length & ((1 << lengthSize) - 1);
        bitOutput.writeInt(true, lengthSize, length);
        for (int i = 0; i < length; i++) {
            bitOutput.writeShort(false, shortSize, value[i]);
        }
        return length;
    }
1167376
def long_out io , level
      indent = " " * level
      @children.each_with_index do |child , i|
        io.write "\n#{indent}" unless i == 0
        io.write "- "
        child.out(io , level + 1)
      end
    end
850672
def array_char_length(input_array)
      length = 0
      input_array.each do |a|
        length += a.to_s.length
      end
      length
    end
1076325
def write_longlong(self, n):
        
        if (n < 0) or (n >= (2**64)):
            raise ValueError('Octet out of range 0..2**64-1')
        self._flushbits()
        self.out.write(pack('>Q', n))
1039386
function array(length, value) {
      var tmpArr = [], tmpVal = 0, i = -1;
      while (++i < length) {
        if (isUdf(value)) {
          tmpArr.push(tmpVal++);
        } else if (isFun(value)) {
          tmpArr.push(value.length > 0 ? value(i) : value());
        } else {
          tmpArr.push(value);
        }
      }
      return tmpArr;
    }
681224
public static int writeLong(ArrayView target, int offset, long value) {
        return writeLong(target.array(), target.arrayOffset() + offset, value);
    }
388601
public static int writeLong(byte[] array, int offset, long v) {
    array[offset + 0] = (byte) (v >>> 56);
    array[offset + 1] = (byte) (v >>> 48);
    array[offset + 2] = (byte) (v >>> 40);
    array[offset + 3] = (byte) (v >>> 32);
    array[offset + 4] = (byte) (v >>> 24);
    array[offset + 5] = (byte) (v >>> 16);
    array[offset + 6] = (byte) (v >>> 8);
    array[offset + 7] = (byte) (v >>> 0);
    return SIZE_LONG;
  }
1132608
@Override
  public void writeLong(long v) throws IOException {
    work[0] = (byte) (0xffL & v);
    work[1] = (byte) (0xffL & (v >> 8));
    work[2] = (byte) (0xffL & (v >> 16));
    work[3] = (byte) (0xffL & (v >> 24));
    work[4] = (byte) (0xffL & (v >> 32));
    work[5] = (byte) (0xffL & (v >> 40));
    work[6] = (byte) (0xffL & (v >> 48));
    work[7] = (byte) (0xffL & (v >> 56));
    write(work, 0, 8);
  }
355252
public static final void writeUTF(OutputStream out,
                                      char[] chars, int offset, int length)
        throws IOException
    {
        for (int i=0; i<length; i++) {
            int c = chars[i + offset];
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out.write(c);
            }
            else if (c > 0x07FF) {
                out.write(0xe0 | ((c >> 12) & 0x0f));
                out.write(0x80 | ((c >> 6) & 0x3f));
                out.write(0x80 | (c & 0x3f));
            }
            else {
                out.write(0xc0 | ((c >> 6) & 0x1f));
                out.write(0x80 | (c & 0x3f));
            }
        }
    }
152666
@Override
	public long writeBooleans(boolean value, long count) {
		count = Math.min(count, size - position - bufferSize);
		if (count == 0) return 0;

		final int bits = value ? -1 : 0;
		long c = count;
		while (c >= 32) {
			flushBuffer();
			bufferBits = bits;
			bufferSize = 32;
			c -= 32;
		}

		int d = (int) c;
		if (d == 0) {
			/* do nothing */
		} else if (bufferSize == 0) {
			bufferBits = bits;
			bufferSize = d;
		} else if (bufferSize + d <= 32) {
			bufferBits <<= d;
			if (value) bufferBits |= preMask(d);
			bufferSize += d;
		} else {
			flushBuffer();
			bufferBits = bits;
			bufferSize = d;
		}

		return count;
	}
403456
public static long[] asLongTypeArray(List<Long> input) {
		long[] result = new long[input.size()];

		for (int i = 0; i < result.length; i++) {
			result[i] = input.get(i);
		}

		return result;
	}
78022
def write_length_and_key(fp, value):
    
    written = write_fmt(fp, 'I', 0 if value in _TERMS else len(value))
    written += write_bytes(fp, value)
    return written
546511
private static void writeLong(byte[] buffer, int offset, long value) {
    buffer[offset    ] = (byte) (value >> 56);
    buffer[offset + 1] = (byte) (value >> 48);
    buffer[offset + 2] = (byte) (value >> 40);
    buffer[offset + 3] = (byte) (value >> 32);
    buffer[offset + 4] = (byte) (value >> 24);
    buffer[offset + 5] = (byte) (value >> 16);
    buffer[offset + 6] = (byte) (value >> 8);
    buffer[offset + 7] = (byte) value;
  }
1228626
public void writeSmallLongArray( long[] values ) {
        int byteSize = values.length * 8 + 1;
        this.addUnsignedByte( ( short ) values.length );
        doWriteLongArray( values, byteSize );
    }