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

Commit

Permalink
Fixed MurmurHash
Browse files Browse the repository at this point in the history
  • Loading branch information
axothy committed Jan 3, 2024
1 parent e0339db commit a5d948d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/java/ru/vk/itmo/chebotinalexandr/MurmurHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public final class MurmurHash {
public static final int DEFAULT_SEED = 104729;
public static final VarHandle LITTLE_ENDIAN_LONG = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_LONG_UNALIGNED);

private MurmurHash() {

Expand Down Expand Up @@ -136,9 +137,7 @@ private static long getBlock(MemorySegment key, int offset, int index) {
int i16 = index << 4; //blocks are 16 bytes
int blockOffset = offset + i16;

ByteBuffer buffer = key.asByteBuffer().order(ByteOrder.nativeOrder());
buffer.position(blockOffset);
return buffer.getLong();
return (long) LITTLE_ENDIAN_LONG.get(key, blockOffset);
}

private static long rotl64(long v, int n) {
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/ru/vk/itmo/chebotinalexandr/NotOnlyInMemoryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ public Entry<MemorySegment> get(MemorySegment key) {
return result.value() == null ? null : result;
}

for (MemorySegment sstable : currState.sstables) {
return getFromDisk(key, currState);
}

private Entry<MemorySegment> getFromDisk(MemorySegment key, State state) {
Entry<MemorySegment> result;

for (MemorySegment sstable : state.sstables) {
if (BloomFilter.sstableMayContain(key, sstable)) {
result = SSTableUtils.get(sstable, key);

Expand All @@ -124,7 +130,13 @@ public Entry<MemorySegment> getNoBloomFilter(MemorySegment key) {
return result.value() == null ? null : result;
}

for (MemorySegment sstable : currState.sstables) {
return getFromDiskNoBloomFilter(key, currState);
}

private Entry<MemorySegment> getFromDiskNoBloomFilter(MemorySegment key, State state) {
Entry<MemorySegment> result;

for (MemorySegment sstable : state.sstables) {
result = SSTableUtils.get(sstable, key);

if (result != null) {
Expand All @@ -135,6 +147,7 @@ public Entry<MemorySegment> getNoBloomFilter(MemorySegment key) {
return null;
}


private PeekingIterator<Entry<MemorySegment>> range(
Iterator<Entry<MemorySegment>> firstIterator,
Iterator<Entry<MemorySegment>> secondIterator,
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/ru/vk/itmo/BasicTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ru.vk.itmo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Timeout;
import org.opentest4j.AssertionFailedError;
import ru.vk.itmo.test.DaoFactory;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

/**
* @author incubos
Expand Down Expand Up @@ -152,4 +155,5 @@ void testHugeData(Dao<String, Entry<String>> dao) throws Exception {
assertSame(dao.get(keyAt(entry)), entryAt(entry));
}
}

}

0 comments on commit a5d948d

Please # to comment.