@Override public void serialize(DataOutput out) throws IOException { // little endian for (long w : bitmap) { out.writeLong(Long.reverseBytes(w)); } }
/** * Converts a byte array to a long value considering it was written in big-endian format. * * @param bytes byte array * @param offset offset into array * @return the long value */ public static long toLong(byte[] bytes, int offset) { if (littleEndian) { return Long.reverseBytes(theUnsafe.getLong(bytes, offset + BYTE_ARRAY_BASE_OFFSET)); } else { return theUnsafe.getLong(bytes, offset + BYTE_ARRAY_BASE_OFFSET); } }
/** * Put a long value out to the specified byte array position in big-endian format. * * @param bytes the byte array * @param offset position in the array * @param val long to write out * @return incremented offset */ public static int putLong(byte[] bytes, int offset, long val) { if (littleEndian) { val = Long.reverseBytes(val); } theUnsafe.putLong(bytes, offset + BYTE_ARRAY_BASE_OFFSET, val); return offset + Bytes.SIZEOF_LONG; }
@Override public long readLong() throws IOException { long l = this.stream.readLong(); if (endianness == ByteOrder.LITTLE_ENDIAN) { l = Long.reverseBytes(l); } return l; }
@Override public void deserialize(DataInput in) throws IOException { // little endian this.cardinality = 0; for (int k = 0; k < bitmap.length; ++k) { bitmap[k] = Long.reverseBytes(in.readLong()); this.cardinality += Long.bitCount(bitmap[k]); } }
/** * Put a long value out to the specified BB position in big-endian format. * * @param buf the byte buffer * @param offset position in the buffer * @param val long to write out * @return incremented offset */ public static int putLong(ByteBuffer buf, int offset, long val) { if (littleEndian) { val = Long.reverseBytes(val); } if (buf.isDirect()) { theUnsafe.putLong(((DirectBuffer) buf).address() + offset, val); } else { theUnsafe.putLong(buf.array(), BYTE_ARRAY_BASE_OFFSET + buf.arrayOffset() + offset, val); } return offset + Bytes.SIZEOF_LONG; }
/** * Reads a long value at the given Object's offset considering it was written in big-endian * format. * * @param ref * @param offset * @return long value at offset */ public static long toLong(Object ref, long offset) { if (littleEndian) { return Long.reverseBytes(theUnsafe.getLong(ref, offset)); } return theUnsafe.getLong(ref, offset); }
/** * Reads a long value at the given buffer's offset considering it was written in big-endian * format. * * @param buf * @param offset * @return long value at offset */ public static long toLong(ByteBuffer buf, int offset) { if (littleEndian) { return Long.reverseBytes(getAsLong(buf, offset)); } return getAsLong(buf, offset); }
public long test_long_reversed(long i) { return Long.reverseBytes(i); }
public void test_copy_longs_store_reversed(long[] dst, long[] src) { for (int i = 0; i < src.length; i++) { dst[i] = Long.reverseBytes(1 + src[i]); } }
@Override protected void _setLong(int index, long value) { PlatformDependent.putLong(addr(index), NATIVE_ORDER ? value : Long.reverseBytes(value)); }
@Override protected long _getLong(int index) { long v = PlatformDependent.getLong(addr(index)); return NATIVE_ORDER ? v : Long.reverseBytes(v); }
@Override public long readLong() throws IOException { final long v = dataInput.readLong(); return bigEndian() ? v : Long.reverseBytes(v); }
@Override public void putLongLittleEndian(byte[] array, int offset, long value) { // Reverse the order of the bytes before storing, since we're on big-endian hardware. long littleEndianValue = Long.reverseBytes(value); theUnsafe.putLong(array, (long) offset + BYTE_ARRAY_BASE_OFFSET, littleEndianValue); }
@Override public long getLongLittleEndian(byte[] array, int offset) { long bigEndian = theUnsafe.getLong(array, (long) offset + BYTE_ARRAY_BASE_OFFSET); // The hardware is big-endian, so we need to reverse the order of the bytes. return Long.reverseBytes(bigEndian); }