Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lehatheslayer committed Feb 1, 2024
1 parent 86c687a commit 85c92e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
24 changes: 2 additions & 22 deletions src/main/java/ru/vk/itmo/reference/SSTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/vk/itmo/reference/SampledIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 85c92e8

Please sign in to comment.