/** * Writes the given long value (64bit, 8 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 #putLong(int, long)}. 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 #putLong(int, long)} 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 putLongLittleEndian(int index, long value) { if (LITTLE_ENDIAN) { putLong(index, value); } else { putLong(index, Long.reverseBytes(value)); } }
/** * Writes the given long 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 #putLong(int, long)}. 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 #putLong(int, long)} 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 putLongBigEndian(int index, long value) { if (LITTLE_ENDIAN) { putLong(index, Long.reverseBytes(value)); } else { putLong(index, value); } }
/** * Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in the * system's native byte order. This method offers the best speed for double writing 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 at which the memory will be written. * @param value The double value to be written. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final void putDouble(int index, double value) { putLong(index, Double.doubleToRawLongBits(value)); }
@Override public Optional<BufferOrEvent> getNextBufferOrEvent() throws IOException, InterruptedException { currentChannel = (currentChannel + 1) % numberOfChannels; if (barrierGens[currentChannel].isNextBarrier()) { return Optional.of( new BufferOrEvent( new CheckpointBarrier( ++currentBarriers[currentChannel], System.currentTimeMillis(), CheckpointOptions.forCheckpointWithDefaultLocation()), currentChannel)); } else { Buffer buffer = bufferPools[currentChannel].requestBuffer(); buffer.getMemorySegment().putLong(0, c++); return Optional.of(new BufferOrEvent(buffer, currentChannel)); } }
segment.putLong(-1, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(pageSize, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(pageSize - 7, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(Integer.MIN_VALUE, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(Integer.MAX_VALUE, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(Integer.MAX_VALUE - 7, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(i, random.nextLong()); segment.putLong(pos, random.nextLong());
/** * Clear the bit set. */ public void clear() { long zeroValue = 0L; for (int i = 0; i < (length / 8); i++) { memorySegment.putLong(offset + i * 8, zeroValue); } }
/** * Clear the bit set. */ public void clear() { long zeroValue = 0L; for (int i = 0; i < (length / 8); i++) { memorySegment.putLong(offset + i * 8, zeroValue); } }
private void resetBucketSegments(List<MemorySegment> resetBucketSegs) { for (MemorySegment segment: resetBucketSegs) { for (int j = 0; j <= lastBucketPosition; j += BUCKET_SIZE) { segment.putLong(j, END_OF_LIST); } } }
/** * Clear the bit set. */ public void clear() { long zeroValue = 0L; for (int i = 0; i < (length / 8); i++) { memorySegment.putLong(offset + i * 8, zeroValue); } }
protected void zeroOutPaddingBytes(int numBytes) { if ((numBytes & 0x07) > 0) { segment.putLong(cursor + ((numBytes >> 3) << 3), 0L); } }
segment.putLong(0, 42); fail("Should fail with an exception"); segment.putLong(-1, 42); fail("Should fail with an exception"); segment.putLong(1, 42); fail("Should fail with an exception"); segment.putLong(segment.size(), 42); fail("Should fail with an exception"); segment.putLong(-segment.size(), 42); fail("Should fail with an exception"); segment.putLong(Integer.MAX_VALUE, 42); fail("Should fail with an exception"); segment.putLong(Integer.MIN_VALUE, 42); fail("Should fail with an exception");
segment.putLong(0, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(1, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(-1, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(8, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(-8, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(Integer.MAX_VALUE, 0L); fail("IndexOutOfBoundsException expected"); segment.putLong(Integer.MIN_VALUE, 0L); fail("IndexOutOfBoundsException expected");
/** * Sets the bit at specified index. * * @param index - position */ public void set(int index) { int longIndex = (index & LONG_POSITION_MASK) >>> 3; long current = memorySegment.getLong(offset + longIndex); current |= (1L << index); memorySegment.putLong(offset + longIndex, current); }
/** * First, reset. */ public void reset() { this.cursor = fixedSize; for (int i = 0; i < nullBitsSizeInBytes; i += 8) { segment.putLong(i, 0L); } this.segment.putInt(0, numElements); }
/** * Sets the bit at specified index. * * @param index - position */ public void set(int index) { int longIndex = (index & LONG_POSITION_MASK) >>> 3; long current = memorySegment.getLong(offset + longIndex); current |= (1L << index); memorySegment.putLong(offset + longIndex, current); }
/** * Write of index and normalizedKey. */ protected void writeIndexAndNormalizedKey(BaseRow record, long currOffset) { // add the pointer and the normalized key this.currentSortIndexSegment.putLong(this.currentSortIndexOffset, currOffset); if (this.numKeyBytes != 0) { normalizedKeyComputer.putKey(record, this.currentSortIndexSegment, this.currentSortIndexOffset + OFFSET_LEN); } this.currentSortIndexOffset += this.indexEntrySize; this.numRecords++; }
@Override public void setOffsetAndSize(int pos, int offset, long size) { final long offsetAndSize = ((long) offset << 32) | size; segment.putLong(getElementOffset(pos, 8), offsetAndSize); }
/** * First, reset. */ public void reset() { resetCursor(); for (int i = 0; i < nullBitsSizeInBytes; i += 8) { segment.putLong(i, 0L); } }
private static void setLongMultiSeg(MemorySegment[] segments, int offset, long value) { int segSize = segments[0].size(); int segIndex = offset / segSize; int segOffset = offset - segIndex * segSize; // equal to % if (segOffset < segSize - 7) { segments[segIndex].putLong(segOffset, value); } else { setLongSlowly(segments, segSize, segIndex, segOffset, value); } }
/** * Sets the bit specified by the index to {@code false}. */ public static void clear(MemorySegment segment, int offset, int index) { checkArgument(index >= 0, "index < 0"); final int wordOffset = offset + wordBytesIndex(index); final long word = segment.getLong(wordOffset); segment.putLong(wordOffset, word & ~(1L << index)); }