add a pointer to the root node
Before the offset of the root node was hard-coded. Now the offset of the pointer to the root node is hard-coded. That allows us to replace the root node.
This commit is contained in:
@@ -5,6 +5,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.lucares.pdb.diskstorage.DiskStorage;
|
||||
import org.lucares.utils.file.FileUtils;
|
||||
@@ -30,17 +31,21 @@ public class PersistentMapTest {
|
||||
|
||||
public void testSingleValue() throws Exception {
|
||||
final Path file = dataDirectory.resolve("map.db");
|
||||
final String value = "value1";
|
||||
final String key = "key1";
|
||||
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
final PersistentMap map = new PersistentMap(ds);
|
||||
|
||||
final String value = "value1";
|
||||
final String key = "key1";
|
||||
|
||||
Assert.assertNull(map.getAsString(key));
|
||||
|
||||
Assert.assertNull(map.put(key, value));
|
||||
|
||||
Assert.assertEquals(map.getAsString(key), value);
|
||||
}
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
final PersistentMap map = new PersistentMap(ds);
|
||||
|
||||
Assert.assertEquals(map.getAsString(key), value);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +57,7 @@ public class PersistentMapTest {
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
final PersistentMap map = new PersistentMap(ds);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
|
||||
final String key = UUID.randomUUID().toString() + "__" + i;
|
||||
final String value = "long value to waste some bytes " + i;
|
||||
@@ -72,11 +77,19 @@ public class PersistentMapTest {
|
||||
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
final PersistentMap map = new PersistentMap(ds);
|
||||
|
||||
map.visitPreOrder((nodeEntry, depth) -> {
|
||||
if (nodeEntry.isInnerNode()) {
|
||||
System.out.println(" ".repeat(depth) + nodeEntry);
|
||||
}
|
||||
});
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
map.visitPreOrder((nodeEntry, depth) -> counter.addAndGet(nodeEntry.isInnerNode() ? 1 : 0));
|
||||
|
||||
// Assert.assertEquals(counter.get(), 3,
|
||||
// "number of nodes should be small. Any number larger than 3 indicates, "
|
||||
// + "that new inner nodes are created even though the existing inner "
|
||||
// + "nodes could hold the values");
|
||||
|
||||
for (final var entry : insertedValues.entrySet()) {
|
||||
final String actualValue = map.getAsString(entry.getKey());
|
||||
|
||||
Reference in New Issue
Block a user