/** * Reads a single-precision floating point value (32bit, 4 bytes) from the given position, in the system's * native byte order. This method offers the best speed for float reading and should be used * unless a specific byte order is required. In most cases, 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 * (such as transient storage in memory, or serialization for I/O and network), making this * method the preferable choice. * * @param index The position from which the value will be read. * @return The float value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 4. */ public final float getFloat(int index) { return Float.intBitsToFloat(getInt(index)); }
/** * Reads an int value (32bit, 4 bytes) from 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 #getInt(int)}. 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 #getInt(int)} is the preferable choice. * * @param index The position from which the value will be read. * @return The int value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 4. */ public final int getIntLittleEndian(int index) { if (LITTLE_ENDIAN) { return getInt(index); } else { return Integer.reverseBytes(getInt(index)); } }
/** * Reads an int value (32bit, 4 bytes) from 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 #getInt(int)}. 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 #getInt(int)} is the preferable choice. * * @param index The position from which the value will be read. * @return The int value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 4. */ public final int getIntBigEndian(int index) { if (LITTLE_ENDIAN) { return Integer.reverseBytes(getInt(index)); } else { return getInt(index); } }
segment.getInt(-1); fail("IndexOutOfBoundsException expected"); segment.getInt(pageSize); fail("IndexOutOfBoundsException expected"); segment.getInt(pageSize - 3); fail("IndexOutOfBoundsException expected"); segment.getInt(Integer.MIN_VALUE); fail("IndexOutOfBoundsException expected"); segment.getInt(Integer.MAX_VALUE); fail("IndexOutOfBoundsException expected"); segment.getInt(Integer.MAX_VALUE - 3); fail("IndexOutOfBoundsException expected"); assertEquals(random.nextInt(), segment.getInt(i)); assertEquals(random.nextInt(), segment.getInt(pos));
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(0); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(0); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(ChannelWriterOutputView.HEAD_BLOCK_LENGTH_OFFSET); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(ChannelWriterOutputView.HEAD_BLOCK_LENGTH_OFFSET); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(ChannelWriterOutputView.HEAD_BLOCK_LENGTH_OFFSET); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(0); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(ChannelWriterOutputView.HEAD_BLOCK_LENGTH_OFFSET); }
@Override protected int getLimitForSegment(MemorySegment segment) { return segment.getInt(0); }
segment.getInt(0); fail("Should fail with an exception"); segment.getInt(-1); fail("Should fail with an exception"); segment.getInt(1); fail("Should fail with an exception"); segment.getInt(segment.size()); fail("Should fail with an exception"); segment.getInt(-segment.size()); fail("Should fail with an exception"); segment.getInt(Integer.MAX_VALUE); fail("Should fail with an exception"); segment.getInt(Integer.MIN_VALUE); fail("Should fail with an exception");
segment.getInt(0); fail("IndexOutOfBoundsException expected"); segment.getInt(1); fail("IndexOutOfBoundsException expected"); segment.getInt(-1); fail("IndexOutOfBoundsException expected"); segment.getInt(8); fail("IndexOutOfBoundsException expected"); segment.getInt(-8); fail("IndexOutOfBoundsException expected"); segment.getInt(Integer.MAX_VALUE); fail("IndexOutOfBoundsException expected"); segment.getInt(Integer.MIN_VALUE); fail("IndexOutOfBoundsException expected");
public static int getInt(MemorySegment[] segments, int offset) { if (segments.length == 1) { return segments[0].getInt(offset); } else { return getIntMultiSeg(segments, offset); } }
private ReadEnd(MemorySegment firstMemSegment, LinkedBlockingQueue<MemorySegment> emptyBufferTarget, Deque<MemorySegment> fullBufferSource, BlockChannelReader<MemorySegment> spilledBufferSource, List<MemorySegment> emptyBuffers, int numBuffersSpilled) throws IOException { super(firstMemSegment, firstMemSegment.getInt(0), HEADER_LENGTH); this.emptyBufferTarget = emptyBufferTarget; this.fullBufferSource = fullBufferSource; this.spilledBufferSource = spilledBufferSource; requestsRemaining = numBuffersSpilled; this.spilledBuffersRemaining = numBuffersSpilled; // send the first requests while (requestsRemaining > 0 && emptyBuffers.size() > 0) { this.spilledBufferSource.readBlock(emptyBuffers.remove(emptyBuffers.size() - 1)); requestsRemaining--; } }
private ReadEnd(MemorySegment firstMemSegment, LinkedBlockingQueue<MemorySegment> emptyBufferTarget, Deque<MemorySegment> fullBufferSource, BlockChannelReader<MemorySegment> spilledBufferSource, List<MemorySegment> emptyBuffers, int numBuffersSpilled) throws IOException { super(firstMemSegment, firstMemSegment.getInt(0), HEADER_LENGTH); this.emptyBufferTarget = emptyBufferTarget; this.fullBufferSource = fullBufferSource; this.spilledBufferSource = spilledBufferSource; requestsRemaining = numBuffersSpilled; this.spilledBuffersRemaining = numBuffersSpilled; // send the first requests while (requestsRemaining > 0 && emptyBuffers.size() > 0) { this.spilledBufferSource.readBlock(emptyBuffers.remove(emptyBuffers.size() - 1)); requestsRemaining--; } }
private static int getIntMultiSeg(MemorySegment[] segments, int offset) { int segSize = segments[0].size(); int segIndex = offset / segSize; int segOffset = offset - segIndex * segSize; // equal to % if (segOffset < segSize - 3) { return segments[segIndex].getInt(segOffset); } else { return getIntSlowly(segments, segSize, segIndex, segOffset); } }
@Override public int getInt(int pos) { assertIndexIsValid(pos); return segment.getInt(getFieldOffset(pos)); }
/** * This is not a public method, please invoke {@link #hashBytesByWords} or {@link #hashBytes}. */ private static int hashBytesByInt( MemorySegment segment, int offset, int lengthInBytes, int seed) { assert (lengthInBytes % 4 == 0); int h1 = seed; for (int i = 0; i < lengthInBytes; i += 4) { int halfWord = segment.getInt(offset + i); int k1 = mixK1(halfWord); h1 = mixH1(h1, k1); } return h1; }