diff --git a/src/jmh/java/com/tomfran/lsm/sstable/SSTableBenchmark.java b/src/jmh/java/com/tomfran/lsm/sstable/SSTableBenchmark.java index 007cd06..bdbd265 100644 --- a/src/jmh/java/com/tomfran/lsm/sstable/SSTableBenchmark.java +++ b/src/jmh/java/com/tomfran/lsm/sstable/SSTableBenchmark.java @@ -45,8 +45,8 @@ public void setup() throws IOException { // sort and divide into inserted and skipped var items = l.stream() - .sorted((a, b) -> ByteArrayComparator.compare(a.key(), b.key())) - .toList(); + .sorted((a, b) -> ByteArrayComparator.compare(a.key(), b.key())) + .toList(); var inserted = new ObjectArrayList(); var skipped = new ObjectArrayList(); @@ -106,4 +106,5 @@ public void negativeAccess(Blackhole bh) { index = (index + 1) % skippedArray.length; } + } diff --git a/src/main/java/com/tomfran/lsm/bloom/BloomFilter.java b/src/main/java/com/tomfran/lsm/bloom/BloomFilter.java index 972c1fd..6662ed2 100644 --- a/src/main/java/com/tomfran/lsm/bloom/BloomFilter.java +++ b/src/main/java/com/tomfran/lsm/bloom/BloomFilter.java @@ -141,4 +141,5 @@ public void writeToFile(String filename) { os.close(); } + } diff --git a/src/main/java/com/tomfran/lsm/io/BaseInputStream.java b/src/main/java/com/tomfran/lsm/io/BaseInputStream.java index 2658e9a..746c666 100644 --- a/src/main/java/com/tomfran/lsm/io/BaseInputStream.java +++ b/src/main/java/com/tomfran/lsm/io/BaseInputStream.java @@ -105,4 +105,5 @@ public void close() { throw new RuntimeException(e); } } + } diff --git a/src/main/java/com/tomfran/lsm/io/BaseOutputStream.java b/src/main/java/com/tomfran/lsm/io/BaseOutputStream.java index 078dc9e..c535205 100644 --- a/src/main/java/com/tomfran/lsm/io/BaseOutputStream.java +++ b/src/main/java/com/tomfran/lsm/io/BaseOutputStream.java @@ -92,4 +92,5 @@ public void close() { throw new RuntimeException(e); } } + } diff --git a/src/main/java/com/tomfran/lsm/memtable/SkipList.java b/src/main/java/com/tomfran/lsm/memtable/SkipList.java index a198e27..d2a0387 100644 --- a/src/main/java/com/tomfran/lsm/memtable/SkipList.java +++ b/src/main/java/com/tomfran/lsm/memtable/SkipList.java @@ -72,7 +72,8 @@ public void add(ByteArrayPair item) { private int randomLevel() { int level = 1; - while (rn.nextBoolean() && level < levels) + long n = rn.nextLong(); + while (level < levels && (n & (1L << level)) != 0) level++; return level; } @@ -155,6 +156,7 @@ public String toString() { } private static final class Node { + ByteArrayPair val; Node[] next; @@ -162,6 +164,7 @@ private static final class Node { this.val = val; this.next = new Node[numLevels]; } + } private record SkipListIterator(Node node) implements Iterator { @@ -175,6 +178,7 @@ public boolean hasNext() { public ByteArrayPair next() { return node.next[0].val; } + } } diff --git a/src/main/java/com/tomfran/lsm/sstable/SSTable.java b/src/main/java/com/tomfran/lsm/sstable/SSTable.java index 51d2853..b00f44e 100644 --- a/src/main/java/com/tomfran/lsm/sstable/SSTable.java +++ b/src/main/java/com/tomfran/lsm/sstable/SSTable.java @@ -273,6 +273,7 @@ public ByteArrayPair next() { remaining--; return table.is.readBytePair(); } + } /** @@ -313,6 +314,7 @@ public ByteArrayPair next() { public Iterator iterator() { return this; } + } } diff --git a/src/main/java/com/tomfran/lsm/tree/LSMTree.java b/src/main/java/com/tomfran/lsm/tree/LSMTree.java index bf57877..660d938 100644 --- a/src/main/java/com/tomfran/lsm/tree/LSMTree.java +++ b/src/main/java/com/tomfran/lsm/tree/LSMTree.java @@ -53,4 +53,5 @@ public byte[] get(byte[] key) { return null; } + } diff --git a/src/main/java/com/tomfran/lsm/types/ByteArrayPair.java b/src/main/java/com/tomfran/lsm/types/ByteArrayPair.java index 82e9203..4b2a581 100644 --- a/src/main/java/com/tomfran/lsm/types/ByteArrayPair.java +++ b/src/main/java/com/tomfran/lsm/types/ByteArrayPair.java @@ -31,4 +31,5 @@ public String toString() { sb.append(")"); return sb.toString(); } + } diff --git a/src/main/java/com/tomfran/lsm/utils/IteratorMerger.java b/src/main/java/com/tomfran/lsm/utils/IteratorMerger.java index f22fefd..bd9cbde 100644 --- a/src/main/java/com/tomfran/lsm/utils/IteratorMerger.java +++ b/src/main/java/com/tomfran/lsm/utils/IteratorMerger.java @@ -60,4 +60,5 @@ public T next() { return result; } + } diff --git a/src/test/java/com/tomfran/lsm/TestUtils.java b/src/test/java/com/tomfran/lsm/TestUtils.java index d97f2ba..dc4aee9 100644 --- a/src/test/java/com/tomfran/lsm/TestUtils.java +++ b/src/test/java/com/tomfran/lsm/TestUtils.java @@ -34,12 +34,13 @@ public static byte[] getRandomByteArray() { public static List getRandomByteArrayList(int size) { return IntStream.range(0, size) - .mapToObj(i -> getRandomByteArray()) - .toList(); + .mapToObj(i -> getRandomByteArray()) + .toList(); } public static void assertPairEqual(ByteArrayPair a, ByteArrayPair b) { assert compare(a.key(), b.key()) == 0; assert compare(a.value(), b.value()) == 0; } + } diff --git a/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java b/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java index 3775c50..f628c44 100644 --- a/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java +++ b/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java @@ -32,9 +32,10 @@ void testAdd() { }); int falsePositives = data.stream().limit(INSERTIONS) - .mapToInt(d -> b.mightContain(d) ? 1 : 0).sum(); + .mapToInt(d -> b.mightContain(d) ? 1 : 0).sum(); double falsePositiveRate = falsePositives / (double) INSERTIONS; results.add(falsePositiveRate); } + } \ No newline at end of file diff --git a/src/test/java/com/tomfran/lsm/bloom/BloomFilterFileTest.java b/src/test/java/com/tomfran/lsm/bloom/BloomFilterFileTest.java index 4d46cc1..3328a8a 100644 --- a/src/test/java/com/tomfran/lsm/bloom/BloomFilterFileTest.java +++ b/src/test/java/com/tomfran/lsm/bloom/BloomFilterFileTest.java @@ -29,4 +29,5 @@ public void shouldReconstruct() { assert bf.bits[i] == bf2.bits[i]; } } + } diff --git a/src/test/java/com/tomfran/lsm/memtable/SkipListTest.java b/src/test/java/com/tomfran/lsm/memtable/SkipListTest.java index 8410217..911d4e1 100644 --- a/src/test/java/com/tomfran/lsm/memtable/SkipListTest.java +++ b/src/test/java/com/tomfran/lsm/memtable/SkipListTest.java @@ -24,8 +24,8 @@ public static void setup() { items = new ObjectArrayList<>(); Stream.generate(TestUtils::getRandomPair) - .limit(100) - .forEach(items::add); + .limit(100) + .forEach(items::add); items.forEach(l::add); } diff --git a/src/test/java/com/tomfran/lsm/sstable/SSTableReconstructTest.java b/src/test/java/com/tomfran/lsm/sstable/SSTableReconstructTest.java index 5f9df10..f7fc56e 100644 --- a/src/test/java/com/tomfran/lsm/sstable/SSTableReconstructTest.java +++ b/src/test/java/com/tomfran/lsm/sstable/SSTableReconstructTest.java @@ -31,8 +31,8 @@ static void setup() throws IOException { } var items = l.stream() - .sorted((a, b) -> compare(a.key(), b.key())) - .toList(); + .sorted((a, b) -> compare(a.key(), b.key())) + .toList(); t1 = new SSTable(tempDirectory + FILE1, items, 3, items.size()); diff --git a/src/test/java/com/tomfran/lsm/sstable/SSTableTest.java b/src/test/java/com/tomfran/lsm/sstable/SSTableTest.java index 539d421..4fdfc39 100644 --- a/src/test/java/com/tomfran/lsm/sstable/SSTableTest.java +++ b/src/test/java/com/tomfran/lsm/sstable/SSTableTest.java @@ -37,8 +37,8 @@ public static void setup() { // sort and divide into inserted and skipped var items = l.stream() - .sorted((a, b) -> ByteArrayComparator.compare(a.key(), b.key())) - .toList(); + .sorted((a, b) -> ByteArrayComparator.compare(a.key(), b.key())) + .toList(); inserted = new ObjectArrayList<>(); skipped = new ObjectArrayList<>(); @@ -88,4 +88,5 @@ public void iteratorTest() { assert !it2.hasNext(); } + } \ No newline at end of file diff --git a/src/test/java/com/tomfran/lsm/utils/IteratorMergerTest.java b/src/test/java/com/tomfran/lsm/utils/IteratorMergerTest.java index 7b348fb..7184a43 100644 --- a/src/test/java/com/tomfran/lsm/utils/IteratorMergerTest.java +++ b/src/test/java/com/tomfran/lsm/utils/IteratorMergerTest.java @@ -14,8 +14,8 @@ class IteratorMergerTest { public void shouldMerge() { List> iteratorList = IntStream.range(0, 10) - .mapToObj(i -> IntStream.range(i * 10, i * 10 + 10).boxed().iterator()) - .collect(Collectors.toList()); + .mapToObj(i -> IntStream.range(i * 10, i * 10 + 10).boxed().iterator()) + .collect(Collectors.toList()); Collections.shuffle(iteratorList);