/** * Reads a short integer value (16 bit, 2 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 #getShort(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 #getShort(int)} is the preferable choice. * * @param index The position from which the value will be read. * @return The short value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final short getShortBigEndian(int index) { if (LITTLE_ENDIAN) { return Short.reverseBytes(getShort(index)); } else { return getShort(index); } }
/** * Reads a short integer value (16 bit, 2 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 #getShort(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 #getShort(int)} is the preferable choice. * * @param index The position from which the value will be read. * @return The short value at the given position. * * @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2. */ public final short getShortLittleEndian(int index) { if (LITTLE_ENDIAN) { return getShort(index); } else { return Short.reverseBytes(getShort(index)); } }
segment.getShort(-1); fail("IndexOutOfBoundsException expected"); segment.getShort(pageSize); fail("IndexOutOfBoundsException expected"); segment.getShort(Integer.MIN_VALUE); fail("IndexOutOfBoundsException expected"); segment.getShort(Integer.MAX_VALUE); fail("IndexOutOfBoundsException expected"); segment.getShort(Integer.MAX_VALUE - 1); fail("IndexOutOfBoundsException expected"); assertEquals((short) random.nextInt(), segment.getShort(i)); assertEquals((short) random.nextInt(), segment.getShort(pos));
public void reset() { this.bucket = this.originalBucket; this.bucketInSegmentOffset = this.originalBucketInSegmentOffset; this.posInSegment = this.bucketInSegmentOffset + BUCKET_HEADER_LENGTH; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; }
public void reset() { this.bucket = this.originalBucket; this.bucketInSegmentOffset = this.originalBucketInSegmentOffset; this.posInSegment = this.bucketInSegmentOffset + BUCKET_HEADER_LENGTH; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; }
public void set(MemorySegment bucket, MemorySegment[] overflowSegments, BinaryHashPartition partition, int searchHashCode, int bucketInSegmentOffset) { this.bucket = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.searchHashCode = searchHashCode; this.bucketInSegmentOffset = bucketInSegmentOffset; this.pointerOffset = bucketInSegmentOffset + BinaryHashBucketArea.BUCKET_POINTER_START_OFFSET; this.hashCodeOffset = this.bucketInSegmentOffset + BinaryHashBucketArea.BUCKET_HEADER_LENGTH; this.countInBucket = bucket.getShort(bucketInSegmentOffset + BinaryHashBucketArea.HEADER_COUNT_OFFSET); this.numInBucket = 0; }
public void reset() { this.bucket = this.originalBucket; this.bucketInSegmentOffset = this.originalBucketInSegmentOffset; this.posInSegment = this.bucketInSegmentOffset + BUCKET_HEADER_LENGTH; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; }
public void reset() { this.bucket = this.originalBucket; this.bucketInSegmentOffset = this.originalBucketInSegmentOffset; this.posInSegment = this.bucketInSegmentOffset + BUCKET_HEADER_LENGTH; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; }
void set(MemorySegment bucket, MemorySegment[] overflowSegments, HashPartition<BT, PT> partition, int searchHashCode, int bucketInSegmentOffset) { this.bucket = bucket; this.originalBucket = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.searchHashCode = searchHashCode; this.bucketInSegmentOffset = bucketInSegmentOffset; this.originalBucketInSegmentOffset = bucketInSegmentOffset; this.posInSegment = this.bucketInSegmentOffset + BUCKET_HEADER_LENGTH; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; }
void set(MemorySegment bucket, MemorySegment[] overflowSegments, HashPartition<BT, PT> partition, int searchHashCode, int bucketInSegmentOffset) { this.bucket = bucket; this.originalBucket = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.searchHashCode = searchHashCode; this.bucketInSegmentOffset = bucketInSegmentOffset; this.originalBucketInSegmentOffset = bucketInSegmentOffset; this.posInSegment = this.bucketInSegmentOffset + BUCKET_HEADER_LENGTH; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; }
segment.getShort(0); fail("Should fail with an exception"); segment.getShort(-1); fail("Should fail with an exception"); segment.getShort(1); fail("Should fail with an exception"); segment.getShort(segment.size()); fail("Should fail with an exception"); segment.getShort(-segment.size()); fail("Should fail with an exception"); segment.getShort(Integer.MAX_VALUE); fail("Should fail with an exception"); segment.getShort(Integer.MIN_VALUE); fail("Should fail with an exception");
private void setBucket(MemorySegment bucket, MemorySegment[] overflowSegments, HashPartition<BT, PT> partition, int bucketInSegmentOffset) { this.bucketSegment = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.bucketInSegmentOffset = bucketInSegmentOffset; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; // reset probedSet with probedFlags offset in this bucket. this.probedSet.setMemorySegment(bucketSegment, this.bucketInSegmentOffset + HEADER_PROBED_FLAGS_OFFSET); }
segment.getShort(0); fail("IndexOutOfBoundsException expected"); segment.getShort(1); fail("IndexOutOfBoundsException expected"); segment.getShort(-1); fail("IndexOutOfBoundsException expected"); segment.getShort(8); fail("IndexOutOfBoundsException expected"); segment.getShort(-8); fail("IndexOutOfBoundsException expected"); segment.getShort(Integer.MAX_VALUE); fail("IndexOutOfBoundsException expected"); segment.getShort(Integer.MIN_VALUE); fail("IndexOutOfBoundsException expected");
private void setBucket(MemorySegment bucket, MemorySegment[] overflowSegments, HashPartition<BT, PT> partition, int bucketInSegmentOffset) { this.bucketSegment = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.bucketInSegmentOffset = bucketInSegmentOffset; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; // reset probedSet with probedFlags offset in this bucket. this.probedSet.setMemorySegment(bucketSegment, this.bucketInSegmentOffset + HEADER_PROBED_FLAGS_OFFSET); }
private void setBucket(MemorySegment bucket, MemorySegment[] overflowSegments, int bucketInSegmentOffset) { this.bucketSegment = bucket; this.overflowSegments = overflowSegments; this.bucketInSegmentOffset = bucketInSegmentOffset; this.pointerOffset = bucketInSegmentOffset + BinaryHashBucketArea.BUCKET_POINTER_START_OFFSET; this.countInBucket = bucket.getShort(bucketInSegmentOffset + BinaryHashBucketArea.HEADER_COUNT_OFFSET); this.numInBucket = 0; // reset probedSet with probedFlags offset in this bucket. this.probedSet.setMemorySegment(bucketSegment, this.bucketInSegmentOffset + BinaryHashBucketArea.PROBED_FLAG_OFFSET); }
private void setBucket(MemorySegment bucket, MemorySegment[] overflowSegments, HashPartition<BT, PT> partition, int bucketInSegmentOffset) { this.bucketSegment = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.bucketInSegmentOffset = bucketInSegmentOffset; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; // reset probedSet with probedFlags offset in this bucket. this.probedSet.setMemorySegment(bucketSegment, this.bucketInSegmentOffset + HEADER_PROBED_FLAGS_OFFSET); }
private void setBucket(MemorySegment bucket, MemorySegment[] overflowSegments, HashPartition<BT, PT> partition, int bucketInSegmentOffset) { this.bucketSegment = bucket; this.overflowSegments = overflowSegments; this.partition = partition; this.bucketInSegmentOffset = bucketInSegmentOffset; this.countInSegment = bucket.getShort(bucketInSegmentOffset + HEADER_COUNT_OFFSET); this.numInSegment = 0; // reset probedSet with probedFlags offset in this bucket. this.probedSet.setMemorySegment(bucketSegment, this.bucketInSegmentOffset + HEADER_PROBED_FLAGS_OFFSET); }
public static short getShort(MemorySegment[] segments, int offset) { if (segments.length == 1) { return segments[0].getShort(offset); } else { return getShortMultiSeg(segments, offset); } }
@Override public short getShort(int pos) { assertIndexIsValid(pos); return segment.getShort(getFieldOffset(pos)); }
private static short getShortMultiSeg(MemorySegment[] segments, int offset) { int segSize = segments[0].size(); int segIndex = offset / segSize; int segOffset = offset - segIndex * segSize; // equal to % if (segOffset < segSize - 1) { return segments[segIndex].getShort(segOffset); } else { return (short) get2ByteSlowly(segments, segSize, segIndex, segOffset); } }