diff --git a/src/main/java/ru/vk/itmo/reference/SSTable.java b/src/main/java/ru/vk/itmo/reference/SSTable.java index 4fad75b6c..08b9e4e0d 100644 --- a/src/main/java/ru/vk/itmo/reference/SSTable.java +++ b/src/main/java/ru/vk/itmo/reference/SSTable.java @@ -71,30 +71,11 @@ private long sampledIndexBinarySearch(final MemorySegment key) { final long keyAtTheStartOffset = sampledIndex.keyAtTheStartOffset(); final long keyAtTheStartLength = sampledIndex.keyAtTheStartLength(); - final long mismatchForStartKey = MemorySegment.mismatch( - data, keyAtTheStartOffset, keyAtTheStartOffset + keyAtTheStartLength, + final int compare = MemorySegmentComparator.compare( + data, keyAtTheStartOffset, keyAtTheStartLength, key, 0L, key.byteSize() ); - final int compare; - if (mismatchForStartKey == -1L) { - // found the necessary key - return sampledIndex.offset(); - } else if (mismatchForStartKey == keyAtTheStartLength) { - // move to the right - low = mid + 1; - continue; - } else if (mismatchForStartKey == key.byteSize()) { - // move to the left - high = mid - 1; - continue; - } - - compare = Byte.compareUnsigned( - data.getAtIndex(ValueLayout.OfByte.JAVA_BYTE, keyAtTheStartOffset + mismatchForStartKey), - key.getAtIndex(ValueLayout.OfByte.JAVA_BYTE, mismatchForStartKey) - ); - if (compare < 0) { low = mid + 1; } else if (compare > 0) { @@ -117,7 +98,6 @@ private long sampledIndexBinarySearch(final MemorySegment key) { */ private long entryBinarySearch(final MemorySegment key) { long low = sampledIndexBinarySearch(key); - System.out.println("low: " + low); long high = low + SAMPLED_INDEX_STEP; while (low <= high) { diff --git a/src/main/java/ru/vk/itmo/reference/SampledIndex.java b/src/main/java/ru/vk/itmo/reference/SampledIndex.java index 24948668b..af104ca7c 100644 --- a/src/main/java/ru/vk/itmo/reference/SampledIndex.java +++ b/src/main/java/ru/vk/itmo/reference/SampledIndex.java @@ -5,5 +5,5 @@ public record SampledIndex( long keyAtTheStartLength, long offset ) { - final static int SAMPLED_INDEX_STEP = 16; + static final int SAMPLED_INDEX_STEP = 16; }