add block size to the header of a PersistentMap and optimize storage
usage for monotonically incrementing keys.
This commit is contained in:
@@ -166,8 +166,9 @@ public class PersistentMapTest {
|
||||
map.visitNodeEntriesPreOrder(
|
||||
(node, parentNode, nodeEntry, depth) -> counter.addAndGet(nodeEntry.isInnerNode() ? 1 : 0));
|
||||
|
||||
Assertions.assertEquals(3, counter.get(),
|
||||
"number of nodes should be small. Any number larger than 3 indicates, "
|
||||
Assertions.assertTrue(5 >= counter.get(),
|
||||
"found " + counter.get()
|
||||
+ " nodes. The 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");
|
||||
|
||||
@@ -194,16 +195,17 @@ public class PersistentMapTest {
|
||||
for (int i = 0; i < 1500; i++) {
|
||||
// System.out.println("\n\ninserting: " + i);
|
||||
|
||||
final Long key = (long) (rnd.nextGaussian() * Integer.MAX_VALUE);
|
||||
final Long key = (long) (rnd.nextGaussian() * 50_000);
|
||||
final Empty value = Empty.INSTANCE;
|
||||
if (map.getValue(key) != null) {
|
||||
continue;
|
||||
}
|
||||
Assertions.assertNull(map.getValue(key));
|
||||
|
||||
Assertions.assertNull(map.putValue(key, value));
|
||||
|
||||
insertedValues.put(key, value);
|
||||
|
||||
// map.print(false);
|
||||
|
||||
final boolean failEarly = false;
|
||||
if (failEarly) {
|
||||
for (final var entry : insertedValues.entrySet()) {
|
||||
@@ -222,13 +224,15 @@ public class PersistentMapTest {
|
||||
|
||||
try (final PersistentMap<Long, Empty> map = new PersistentMap<>(file, dataDirectory, PersistentMap.LONG_CODER,
|
||||
PersistentMap.EMPTY_ENCODER)) {
|
||||
// map.print(false);
|
||||
// map.printNodes();
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
map.visitNodeEntriesPreOrder(
|
||||
(node, parentNode, nodeEntry, depth) -> counter.addAndGet(nodeEntry.isInnerNode() ? 1 : 0));
|
||||
|
||||
Assertions.assertEquals(3, counter.get(),
|
||||
"number of nodes should be small. Any number larger than 3 indicates, "
|
||||
Assertions.assertTrue(5 >= counter.get(),
|
||||
"found " + counter.get()
|
||||
+ " nodes. The number of nodes should be small. Any number larger than 5 indicates, "
|
||||
+ "that new inner nodes are created even though the existing inner "
|
||||
+ "nodes could hold the values");
|
||||
|
||||
@@ -238,6 +242,8 @@ public class PersistentMapTest {
|
||||
"value for key " + entry.getKey() + " after all iterations");
|
||||
}
|
||||
|
||||
map.reindex();
|
||||
// map.printNodes();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +284,7 @@ public class PersistentMapTest {
|
||||
|
||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, dataDirectory,
|
||||
PersistentMap.STRING_CODER, PersistentMap.STRING_CODER)) {
|
||||
// map.print(PersistentMap.STRING_DECODER, PersistentMap.STRING_DECODER);
|
||||
// map.printNodes();
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
map.visitNodeEntriesPreOrder(
|
||||
@@ -377,14 +383,11 @@ public class PersistentMapTest {
|
||||
maxDepth.set(Math.max(maxDepth.get(), depth));
|
||||
});
|
||||
|
||||
final long start = System.nanoTime();
|
||||
for (final var entry : insertedValues.entrySet()) {
|
||||
final Long actualValue = map.getValue(entry.getKey());
|
||||
Assertions.assertEquals(entry.getValue(), actualValue,
|
||||
"value for key " + entry.getKey() + " after all iterations");
|
||||
}
|
||||
System.out.println("nodes=" + counter.get() + ", depth=" + maxDepth.get() + ": "
|
||||
+ (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||
}
|
||||
|
||||
private Map<Long, Long> fillMap(final int numberOfValues, final boolean failEarly,
|
||||
|
||||
Reference in New Issue
Block a user