/** * Writes the given single-precision float value (32bit, 4 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 #putFloat(int, float)}. 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 #putFloat(int, float)} 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 putFloatBigEndian(int index, float value) { putIntBigEndian(index, Float.floatToRawIntBits(value)); }
@Override public void copyNormalizedKey(MemorySegment target, int offset, int len) { // take out value and add the integer min value. This gets an offset // representation when interpreted as an unsigned integer (as is the case // with normalized keys). write this value as big endian to ensure the // most significant byte comes first. if (len == 4) { target.putIntBigEndian(offset, value - Integer.MIN_VALUE); } else if (len <= 0) { } else if (len < 4) { int value = this.value - Integer.MIN_VALUE; for (int i = 0; len > 0; len--, i++) { target.put(offset + i, (byte) ((value >>> ((3-i)<<3)) & 0xff)); } } else { target.putIntBigEndian(offset, value - Integer.MIN_VALUE); for (int i = 4; i < len; i++) { target.put(offset + i, (byte) 0); } } }
@Override public void putNormalizedKey(java.util.Date record, MemorySegment target, int offset, int numBytes) { // put Date key DateComparator.putNormalizedKeyDate(record, target, offset, numBytes > 8 ? 8 : numBytes); numBytes -= 8; offset += 8; if (numBytes <= 0) { // nothing to do } // put nanos else if (numBytes < 4) { final int nanos = ((Timestamp) record).getNanos(); for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (nanos >>> ((3-i)<<3))); } } // put nanos with padding else { final int nanos = ((Timestamp) record).getNanos(); target.putIntBigEndian(offset, nanos); 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 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, Integer.reverseBytes(r)); segment.putIntBigEndian(pos, val); r = segment.getIntLittleEndian(pos); assertEquals(val, Integer.reverseBytes(r));
@Override protected void _setInt(int index, int value) { memorySegment.putIntBigEndian(index, value); }
@Override protected void _setInt(int index, int value) { memorySegment.putIntBigEndian(index, value); }
@Override protected void _setInt(int index, int value) { memorySegment.putIntBigEndian(index, value); }
/** * Writes the given single-precision float value (32bit, 4 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 #putFloat(int, float)}. 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 #putFloat(int, float)} 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 putFloatBigEndian(int index, float value) { putIntBigEndian(index, Float.floatToRawIntBits(value)); }
/** * Writes the given single-precision float value (32bit, 4 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 #putFloat(int, float)}. 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 #putFloat(int, float)} 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 putFloatBigEndian(int index, float value) { putIntBigEndian(index, Float.floatToRawIntBits(value)); }
public static void putUnsignedIntegerNormalizedKey(int value, MemorySegment target, int offset, int numBytes) { if (numBytes == 4) { // default case, full normalized key target.putIntBigEndian(offset, value); } else if (numBytes > 0) { if (numBytes < 4) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((3 - i) << 3))); } } else { target.putIntBigEndian(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(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 writeInt(int v) throws IOException { if (this.positionInSegment < this.segmentSize - 3) { this.currentSegment.putIntBigEndian(this.positionInSegment, v); this.positionInSegment += 4; } else if (this.positionInSegment == this.segmentSize) { advance(); writeInt(v); } else { writeByte(v >> 24); writeByte(v >> 16); writeByte(v >> 8); writeByte(v); } }
@Override public void writeInt(int v) throws IOException { if (this.positionInSegment < this.segmentSize - 3) { this.currentSegment.putIntBigEndian(this.positionInSegment, v); this.positionInSegment += 4; } else if (this.positionInSegment == this.segmentSize) { advance(); writeInt(v); } else { writeByte(v >> 24); writeByte(v >> 16); writeByte(v >> 8); writeByte(v); } }
@Override public void writeInt(int v) throws IOException { if (this.positionInSegment < this.segmentSize - 3) { this.currentSegment.putIntBigEndian(this.positionInSegment, v); this.positionInSegment += 4; } else if (this.positionInSegment == this.segmentSize) { advance(); writeInt(v); } else { writeByte(v >> 24); writeByte(v >> 16); writeByte(v >> 8); writeByte(v); } }
@Override public void writeInt(int v) throws IOException { if (this.positionInSegment < this.segmentSize - 3) { this.currentSegment.putIntBigEndian(this.positionInSegment, v); this.positionInSegment += 4; } else if (this.positionInSegment == this.segmentSize) { advance(); writeInt(v); } else { writeByte(v >> 24); writeByte(v >> 16); writeByte(v >> 8); writeByte(v); } }