From fde2dc0432608f832e5a00f577cdf8e92a37daf0 Mon Sep 17 00:00:00 2001 From: Fran Date: Fri, 13 Oct 2023 14:25:57 +0200 Subject: [PATCH] minor --- src/main/java/com/tomfran/lsm/memtable/Memtable.java | 3 ++- src/main/java/com/tomfran/lsm/sstable/SSTable.java | 6 +++--- .../java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tomfran/lsm/memtable/Memtable.java b/src/main/java/com/tomfran/lsm/memtable/Memtable.java index 19aeefc..d47a602 100644 --- a/src/main/java/com/tomfran/lsm/memtable/Memtable.java +++ b/src/main/java/com/tomfran/lsm/memtable/Memtable.java @@ -1,6 +1,7 @@ package com.tomfran.lsm.memtable; import com.tomfran.lsm.types.ByteArrayPair; +import com.tomfran.lsm.utils.UniqueSortedIterator; import java.util.Iterator; @@ -34,7 +35,7 @@ public int size() { @Override public Iterator iterator() { - return list.iterator(); + return new UniqueSortedIterator<>(list.iterator()); } } diff --git a/src/main/java/com/tomfran/lsm/sstable/SSTable.java b/src/main/java/com/tomfran/lsm/sstable/SSTable.java index fbede44..13d3867 100644 --- a/src/main/java/com/tomfran/lsm/sstable/SSTable.java +++ b/src/main/java/com/tomfran/lsm/sstable/SSTable.java @@ -12,6 +12,7 @@ import java.io.File; import java.util.Iterator; +import java.util.List; import static com.tomfran.lsm.comparator.ByteArrayComparator.compare; import static java.util.Arrays.stream; @@ -257,9 +258,8 @@ private void writeItems(String filename, Iterator items, int samp } public void deleteFiles() { - new File(filename + DATA_FILE_EXTENSION).delete(); - new File(filename + INDEX_FILE_EXTENSION).delete(); - new File(filename + BLOOM_FILE_EXTENSION).delete(); + for (var extension : List.of(DATA_FILE_EXTENSION, INDEX_FILE_EXTENSION, BLOOM_FILE_EXTENSION)) + new File(filename + extension).delete(); } private static class SSTableIterator implements Iterator { diff --git a/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java b/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java index f628c44..d032855 100644 --- a/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java +++ b/src/test/java/com/tomfran/lsm/bloom/BloomFilterAccuracyTest.java @@ -21,7 +21,7 @@ static void tearDown() { "False positive rate is not close to the expected value: " + avg; } - @RepeatedTest(10) + @RepeatedTest(5) void testAdd() { b = new BloomFilter(INSERTIONS, FALSE_POSITIVE_RATE);