/** * Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in big endian * byte order. This method's speed depends on the system's native byte order, and it * is possibly slower than {@link #putDouble(int, double)}. For most cases (such as * transient storage in memory or serialization for I/O and network), * it suffices to know that the byte order in which the value is written is the same as the * one in which it is read, and {@link #putDouble(int, double)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The long value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final void putDoubleBigEndian(int index, double value) { putLongBigEndian(index, Double.doubleToRawLongBits(value)); }
public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset, int numBytes) { final long value = record.getTime() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } } }
@Override public void copyNormalizedKey(MemorySegment target, int offset, int len) { // see IntValue for an explanation of the logic if (len == 8) { // default case, full normalized key target.putLongBigEndian(offset, value - Long.MIN_VALUE); } else if (len <= 0) { } else if (len < 8) { long value = this.value - Long.MIN_VALUE; for (int i = 0; len > 0; len--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value - Long.MIN_VALUE); for (int i = 8; i < len; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void putNormalizedKey(Long lValue, MemorySegment target, int offset, int numBytes) { long value = lValue.longValue() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes <= 0) { } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void putNormalizedKey(Integer iValue, MemorySegment target, int offset, int numBytes) { int value = iValue.intValue() - Integer.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 4) { // default case, full normalized key target.putIntBigEndian(offset, value); } else if (numBytes <= 0) { } else if (numBytes < 4) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((3-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 4; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void putNormalizedKey(T iValue, MemorySegment target, int offset, int numBytes) { int value = iValue.ordinal() - Integer.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 4) { // default case, full normalized key target.putIntBigEndian(offset, value); } else if (numBytes <= 0) { } else if (numBytes < 4) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((3-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 4; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void putNormalizedKey(Instant record, MemorySegment target, int offset, int numBytes) { final int secondsBytes = InstantSerializer.SECONDS_BYTES; final long normalizedSeconds = record.getEpochSecond() - SECONDS_MIN_VALUE; if (numBytes >= secondsBytes) { target.putLongBigEndian(offset, normalizedSeconds); offset += secondsBytes; numBytes -= secondsBytes; final int nanosBytes = InstantSerializer.NANOS_BYTES; if (numBytes >= nanosBytes) { target.putIntBigEndian(offset, record.getNano()); offset += nanosBytes; numBytes -= nanosBytes; for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } else { final int nanos = record.getNano(); for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) (nanos >>> ((3 - i) << 3))); } } } else { for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) (normalizedSeconds >>> ((7 - i) << 3))); } } }
assertEquals(val, Long.reverseBytes(r)); segment.putLongBigEndian(pos, val); r = segment.getLongLittleEndian(pos); assertEquals(val, Long.reverseBytes(r));
@Override protected void _setLong(int index, long value) { memorySegment.putLongBigEndian(index, value); }
@Override protected void _setLong(int index, long value) { memorySegment.putLongBigEndian(index, value); }
@Override protected void _setLong(int index, long value) { memorySegment.putLongBigEndian(index, value); }
/** * Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in big endian * byte order. This method's speed depends on the system's native byte order, and it * is possibly slower than {@link #putDouble(int, double)}. For most cases (such as * transient storage in memory or serialization for I/O and network), * it suffices to know that the byte order in which the value is written is the same as the * one in which it is read, and {@link #putDouble(int, double)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The long value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final void putDoubleBigEndian(int index, double value) { putLongBigEndian(index, Double.doubleToRawLongBits(value)); }
/** * Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in big endian * byte order. This method's speed depends on the system's native byte order, and it * is possibly slower than {@link #putDouble(int, double)}. For most cases (such as * transient storage in memory or serialization for I/O and network), * it suffices to know that the byte order in which the value is written is the same as the * one in which it is read, and {@link #putDouble(int, double)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The long value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final void putDoubleBigEndian(int index, double value) { putLongBigEndian(index, Double.doubleToRawLongBits(value)); }
public static void putUnsignedLongNormalizedKey(long value, MemorySegment target, int offset, int numBytes) { if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes > 0) { if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7 - i) << 3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } } } }
public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset, int numBytes) { final long value = record.getTime() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } } }
public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset, int numBytes) { final long value = record.getTime() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } } }
@Override public void putNormalizedKey(T iValue, MemorySegment target, int offset, int numBytes) { int value = iValue.ordinal() - Integer.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 4) { // default case, full normalized key target.putIntBigEndian(offset, value); } else if (numBytes <= 0) { } else if (numBytes < 4) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((3-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 4; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void putNormalizedKey(Integer iValue, MemorySegment target, int offset, int numBytes) { int value = iValue.intValue() - Integer.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 4) { // default case, full normalized key target.putIntBigEndian(offset, value); } else if (numBytes <= 0) { } else if (numBytes < 4) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((3-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 4; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void writeLong(long v) throws IOException { if (this.positionInSegment < this.segmentSize - 7) { this.currentSegment.putLongBigEndian(this.positionInSegment, v); this.positionInSegment += 8; } else if (this.positionInSegment == this.segmentSize) { advance(); writeLong(v); } else { writeByte((int) (v >> 56)); writeByte((int) (v >> 48)); writeByte((int) (v >> 40)); writeByte((int) (v >> 32)); writeByte((int) (v >> 24)); writeByte((int) (v >> 16)); writeByte((int) (v >> 8)); writeByte((int) v); } }
@Override public void writeLong(long v) throws IOException { if (this.positionInSegment < this.segmentSize - 7) { this.currentSegment.putLongBigEndian(this.positionInSegment, v); this.positionInSegment += 8; } else if (this.positionInSegment == this.segmentSize) { advance(); writeLong(v); } else { writeByte((int) (v >> 56)); writeByte((int) (v >> 48)); writeByte((int) (v >> 40)); writeByte((int) (v >> 32)); writeByte((int) (v >> 24)); writeByte((int) (v >> 16)); writeByte((int) (v >> 8)); writeByte((int) v); } }