-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed LSM tree not flushing, cleanup SSTable iterators, added toy con…
…sole
- Loading branch information
Showing
16 changed files
with
189 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/tomfran/lsm/utils/UniqueSortedIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.tomfran.lsm.utils; | ||
|
||
import java.util.Iterator; | ||
|
||
/** | ||
* Skip duplicates in a sorted iterator by keeping only the first one. | ||
* <p> | ||
* Reads after the last element of the last Iterator will return null. | ||
* | ||
* @param <T> The type of the elements in the Iterators. | ||
*/ | ||
public class UniqueSortedIterator<T extends Comparable<T>> implements Iterator<T> { | ||
|
||
Iterator<T> iterator; | ||
private T last; | ||
|
||
public UniqueSortedIterator(Iterator<T> iterator) { | ||
this.iterator = iterator; | ||
last = iterator.next(); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return last != null; | ||
} | ||
|
||
@Override | ||
public T next() { | ||
T next = iterator.next(); | ||
while (next != null && last.compareTo(next) == 0) | ||
next = iterator.next(); | ||
|
||
T toReturn = last; | ||
last = next; | ||
|
||
return toReturn; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/com/tomfran/lsm/memtable/SkipListIteratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.tomfran.lsm.memtable; | ||
|
||
import com.tomfran.lsm.comparator.ByteArrayComparator; | ||
import com.tomfran.lsm.types.ByteArrayPair; | ||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static com.tomfran.lsm.TestUtils.getRandomPair; | ||
import static com.tomfran.lsm.comparator.ByteArrayComparator.compare; | ||
|
||
public class SkipListIteratorTest { | ||
|
||
static int NUM_ITEMS = 10; | ||
static SkipList list; | ||
static List<ByteArrayPair> items; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
|
||
list = new SkipList(NUM_ITEMS); | ||
|
||
// generate random items | ||
var l = new ObjectOpenHashSet<ByteArrayPair>(); | ||
for (int i = 0; i < NUM_ITEMS; i++) { | ||
l.add(getRandomPair()); | ||
} | ||
|
||
items = l.stream() | ||
.sorted((a, b) -> ByteArrayComparator.compare(a.key(), b.key())) | ||
.toList(); | ||
|
||
items.forEach(list::add); | ||
} | ||
|
||
@Test | ||
public void iteratorTest() { | ||
var it = list.iterator(); | ||
var it2 = items.iterator(); | ||
|
||
while (it.hasNext()) { | ||
var a = it.next(); | ||
var b = it2.next(); | ||
assert compare(a.key(), b.key()) == 0; | ||
assert compare(a.value(), b.value()) == 0; | ||
} | ||
|
||
assert !it2.hasNext(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.