/** * Writes the given short integer value (16 bit, 2 bytes) to the given position in little-endian * byte order. This method's speed depends on the system's native byte order, and it * is possibly slower than {@link #putShort(int, short)}. 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 #putShort(int, short)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The short value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final void putShortLittleEndian(int index, short value) { if (LITTLE_ENDIAN) { putShort(index, value); } else { putShort(index, Short.reverseBytes(value)); } }
/** * Writes the given short integer value (16 bit, 2 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 #putShort(int, short)}. 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 #putShort(int, short)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The short value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final void putShortBigEndian(int index, short value) { if (LITTLE_ENDIAN) { putShort(index, Short.reverseBytes(value)); } else { putShort(index, value); } }
segment.putShort(-1, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(pageSize, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(Integer.MIN_VALUE, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(Integer.MAX_VALUE, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(Integer.MAX_VALUE - 1, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(i, (short) random.nextInt()); segment.putShort(pos, (short) random.nextInt());
segment.putShort(0, (short) 42); fail("Should fail with an exception"); segment.putShort(-1, (short) 42); fail("Should fail with an exception"); segment.putShort(1, (short) 42); fail("Should fail with an exception"); segment.putShort(segment.size(), (short) 42); fail("Should fail with an exception"); segment.putShort(-segment.size(), (short) 42); fail("Should fail with an exception"); segment.putShort(Integer.MAX_VALUE, (short) 42); fail("Should fail with an exception"); segment.putShort(Integer.MIN_VALUE, (short) 42); fail("Should fail with an exception");
/** * Writes the given short integer value (16 bit, 2 bytes) to the given position in little-endian * byte order. This method's speed depends on the system's native byte order, and it * is possibly slower than {@link #putShort(int, short)}. 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 #putShort(int, short)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The short value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final void putShortLittleEndian(int index, short value) { if (LITTLE_ENDIAN) { putShort(index, value); } else { putShort(index, Short.reverseBytes(value)); } }
segment.putShort(0, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(1, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(-1, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(8, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(-8, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(Integer.MAX_VALUE, (short) 0); fail("IndexOutOfBoundsException expected"); segment.putShort(Integer.MIN_VALUE, (short) 0); fail("IndexOutOfBoundsException expected");
/** * Writes the given short integer value (16 bit, 2 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 #putShort(int, short)}. 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 #putShort(int, short)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The short value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final void putShortBigEndian(int index, short value) { if (LITTLE_ENDIAN) { putShort(index, Short.reverseBytes(value)); } else { putShort(index, value); } }
private void writeSegment(MemorySegment segment, int writePosition, boolean lastSegment) throws IOException { segment.putShort(0, HEADER_MAGIC_NUMBER); segment.putShort(HEADER_FLAGS_OFFSET, lastSegment ? FLAG_LAST_BLOCK : 0); segment.putInt(HEAD_BLOCK_LENGTH_OFFSET, writePosition); this.writer.writeBlock(segment); this.bytesBeforeSegment += writePosition - HEADER_LENGTH; } }
/** * Writes the given short integer value (16 bit, 2 bytes) to the given position in little-endian * byte order. This method's speed depends on the system's native byte order, and it * is possibly slower than {@link #putShort(int, short)}. 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 #putShort(int, short)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The short value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final void putShortLittleEndian(int index, short value) { if (LITTLE_ENDIAN) { putShort(index, value); } else { putShort(index, Short.reverseBytes(value)); } }
/** * Writes the given short integer value (16 bit, 2 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 #putShort(int, short)}. 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 #putShort(int, short)} is the preferable choice. * * @param index The position at which the value will be written. * @param value The short value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final void putShortBigEndian(int index, short value) { if (LITTLE_ENDIAN) { putShort(index, Short.reverseBytes(value)); } else { putShort(index, value); } }
private void writeSegment(MemorySegment segment, int writePosition, boolean lastSegment) throws IOException { segment.putShort(0, HEADER_MAGIC_NUMBER); segment.putShort(HEADER_FLAGS_OFFSET, lastSegment ? FLAG_LAST_BLOCK : 0); segment.putInt(HEAD_BLOCK_LENGTH_OFFSET, writePosition); this.writer.writeBlock(segment); this.bytesBeforeSegment += writePosition - HEADER_LENGTH; } }
private void writeSegment(MemorySegment segment, int writePosition, boolean lastSegment) throws IOException { segment.putShort(0, HEADER_MAGIC_NUMBER); segment.putShort(HEADER_FLAGS_OFFSET, lastSegment ? FLAG_LAST_BLOCK : 0); segment.putInt(HEAD_BLOCK_LENGTH_OFFSET, writePosition); this.writer.writeBlock(segment); this.bytesBeforeSegment += writePosition - HEADER_LENGTH; } }
private void writeSegment(MemorySegment segment, int writePosition, boolean lastSegment) throws IOException { segment.putShort(0, HEADER_MAGIC_NUMBER); segment.putShort(HEADER_FLAGS_OFFSET, lastSegment ? FLAG_LAST_BLOCK : 0); segment.putInt(HEAD_BLOCK_LENGTH_OFFSET, writePosition); this.writer.writeBlock(segment); this.bytesBeforeSegment += writePosition - HEADER_LENGTH; } }
public static void setShort(MemorySegment[] segments, int offset, short value) { if (segments.length == 1) { segments[0].putShort(offset, value); } else { setShortMultiSeg(segments, offset, value); } }
@Override public void writeShort(int pos, short value) { segment.putShort(getElementOffset(pos, 2), value); }
@Override public void writeShort(int pos, short value) { segment.putShort(getFieldOffset(pos), value); }
private static void setShortMultiSeg(MemorySegment[] segments, int offset, short value) { int segSize = segments[0].size(); int segIndex = offset / segSize; int segOffset = offset - segIndex * segSize; // equal to % if (segOffset < segSize - 1) { segments[segIndex].putShort(segOffset, value); } else { set2ByteSlowly(segments, segSize, segIndex, segOffset, value, value >> 8); } }
public void setNullShort(int ordinal) { setNullBit(ordinal); // put zero into the corresponding field when set null segment.putShort(getElementOffset(ordinal, 2), (short) 0); }
@Override public void setShort(int pos, short value) { assertIndexIsValid(pos); setNotNullAt(pos); segment.putShort(getFieldOffset(pos), value); }