/** * Reads a long integer value (64bit, 8 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 #getLong(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 #getLong(int)} is the preferable choice. * * @param index The position from which the value will be read. * @return The long value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final long getLongLittleEndian(int index) { if (LITTLE_ENDIAN) { return getLong(index); } else { return Long.reverseBytes(getLong(index)); } }
/** * Reads a double-precision floating point value (64bit, 8 bytes) from the given position, in the system's * native byte order. This method offers the best speed for double 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 double value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final double getDouble(int index) { return Double.longBitsToDouble(getLong(index)); }
/** * Reads a long integer value (64bit, 8 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 #getLong(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 #getLong(int)} is the preferable choice. * * @param index The position from which the value will be read. * @return The long value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment * size minus 8. */ public final long getLongBigEndian(int index) { if (LITTLE_ENDIAN) { return Long.reverseBytes(getLong(index)); } else { return getLong(index); } }
segment.getLong(-1); fail("IndexOutOfBoundsException expected"); segment.getLong(pageSize); fail("IndexOutOfBoundsException expected"); segment.getLong(pageSize - 7); fail("IndexOutOfBoundsException expected"); segment.getLong(Integer.MIN_VALUE); fail("IndexOutOfBoundsException expected"); segment.getLong(Integer.MAX_VALUE); fail("IndexOutOfBoundsException expected"); segment.getLong(Integer.MAX_VALUE - 7); fail("IndexOutOfBoundsException expected"); assertEquals(random.nextLong(), segment.getLong(i)); assertEquals(random.nextLong(), segment.getLong(pos));
/** * Returns true if the bit is set in the specified index. * * @param index - position * @return - value at the bit position */ public boolean get(int index) { int longIndex = (index & LONG_POSITION_MASK) >>> 3; long current = memorySegment.getLong(offset + longIndex); return (current & (1L << index)) != 0; }
/** * Returns true if the bit is set in the specified index. * * @param index - position * @return - value at the bit position */ public boolean get(int index) { int longIndex = (index & LONG_POSITION_MASK) >>> 3; long current = memorySegment.getLong(offset + longIndex); return (current & (1L << index)) != 0; }
/** * Returns true if the bit is set in the specified index. * * @param index - position * @return - value at the bit position */ public boolean get(int index) { int longIndex = (index & LONG_POSITION_MASK) >>> 3; long current = memorySegment.getLong(offset + longIndex); return (current & (1L << index)) != 0; }
/** * Returns true if the bit is set in the specified index. * * @param index - position * @return - value at the bit position */ public boolean get(int index) { int longIndex = (index & LONG_POSITION_MASK) >>> 3; long current = memorySegment.getLong(offset + longIndex); return (current & (1L << index)) != 0; }
segment.getLong(0); fail("Should fail with an exception"); segment.getLong(-1); fail("Should fail with an exception"); segment.getLong(1); fail("Should fail with an exception"); segment.getLong(segment.size()); fail("Should fail with an exception"); segment.getLong(-segment.size()); fail("Should fail with an exception"); segment.getLong(Integer.MAX_VALUE); fail("Should fail with an exception"); segment.getLong(Integer.MIN_VALUE); fail("Should fail with an exception");
private long readPointer(int logicalPosition) { if (logicalPosition < 0 || logicalPosition >= this.numRecords) { throw new IndexOutOfBoundsException(); } final int bufferNum = logicalPosition / this.indexEntriesPerSegment; final int segmentOffset = logicalPosition % this.indexEntriesPerSegment; return (this.sortIndex.get(bufferNum).getLong(segmentOffset * this.indexEntrySize)) & POINTER_MASK; }
segment.getLong(0); fail("IndexOutOfBoundsException expected"); segment.getLong(1); fail("IndexOutOfBoundsException expected"); segment.getLong(-1); fail("IndexOutOfBoundsException expected"); segment.getLong(8); fail("IndexOutOfBoundsException expected"); segment.getLong(-8); fail("IndexOutOfBoundsException expected"); segment.getLong(Integer.MAX_VALUE); fail("IndexOutOfBoundsException expected"); segment.getLong(Integer.MIN_VALUE); 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); }
@Override public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ) { final MemorySegment segI = this.sortIndex.get(segmentNumberI); final MemorySegment segJ = this.sortIndex.get(segmentNumberJ); int val = segI.compare(segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes); if (val != 0 || this.normalizedKeyFullyDetermines) { return this.useNormKeyUninverted ? val : -val; } final long pointerI = segI.getLong(segmentOffsetI) & POINTER_MASK; final long pointerJ = segJ.getLong(segmentOffsetJ) & POINTER_MASK; return compareRecords(pointerI, pointerJ); }
@Override public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ) { final MemorySegment segI = this.sortIndex.get(segmentNumberI); final MemorySegment segJ = this.sortIndex.get(segmentNumberJ); int val = segI.compare(segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes); if (val != 0 || this.normalizedKeyFullyDetermines) { return this.useNormKeyUninverted ? val : -val; } final long pointerI = segI.getLong(segmentOffsetI) & POINTER_MASK; final long pointerJ = segJ.getLong(segmentOffsetJ) & POINTER_MASK; return compareRecords(pointerI, pointerJ); }
/** * 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); }
@Override public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ) { final MemorySegment segI = this.sortIndex.get(segmentNumberI); final MemorySegment segJ = this.sortIndex.get(segmentNumberJ); int val = segI.compare(segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes); if (val != 0 || this.normalizedKeyFullyDetermines) { return this.useNormKeyUninverted ? val : -val; } final long pointerI = segI.getLong(segmentOffsetI) & POINTER_MASK; final long pointerJ = segJ.getLong(segmentOffsetJ) & POINTER_MASK; return compareRecords(pointerI, pointerJ); }
/** * 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); }
/** * 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)); }
@Override public BinaryString getBinaryString(int pos, BinaryString reuse) { assertIndexIsValid(pos); int fieldOffset = getFieldOffset(pos); final long offsetAndSize = segment.getLong(fieldOffset); getBinaryStringFromSeg(allSegments, baseOffset, fieldOffset, offsetAndSize, reuse); return reuse; }