提交 5b811571 authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent tree map (work in progress)

上级 b655f8e8
...@@ -8,8 +8,10 @@ package org.h2.test.unit; ...@@ -8,8 +8,10 @@ package org.h2.test.unit;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
import java.util.TreeMap; import java.util.TreeMap;
import org.h2.dev.store.StoredMap; import org.h2.dev.store.btree.BtreeMap;
import org.h2.dev.store.TreeMapStore; import org.h2.dev.store.btree.BtreeMapStore;
import org.h2.dev.store.tree.StoredMap;
import org.h2.dev.store.tree.TreeMapStore;
import org.h2.jaqu.bytecode.Null; import org.h2.jaqu.bytecode.Null;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -29,6 +31,10 @@ public class TestTreeMapStore extends TestBase { ...@@ -29,6 +31,10 @@ public class TestTreeMapStore extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
// btree
testBtreeStore();
// left leaning red-black tree
testDefragment(); testDefragment();
testReuseSpace(); testReuseSpace();
testRandom(); testRandom();
...@@ -37,6 +43,31 @@ public class TestTreeMapStore extends TestBase { ...@@ -37,6 +43,31 @@ public class TestTreeMapStore extends TestBase {
testSimple(); testSimple();
} }
private void testBtreeStore() {
String fileName = getBaseDir() + "/data.h3";
FileUtils.delete(fileName);
BtreeMapStore s = BtreeMapStore.open(fileName);
BtreeMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
int count = 5;
for (int i = 0; i < count; i++) {
m.put(i, "hello " + i);
}
s.store();
m.remove(0);
assertNull(m.get(0));
for (int i = 1; i < count; i++) {
assertEquals("hello " + i, m.get(i));
}
s.close();
// s = BtreeMapStore.open(fileName);
// m = s.openMap("data", Integer.class, String.class);
// assertNull(m.get(0));
// for (int i = 1; i < count; i++) {
// assertEquals("hello " + i, m.get(i));
// }
// s.close();
}
private void testDefragment() { private void testDefragment() {
String fileName = getBaseDir() + "/data.h3"; String fileName = getBaseDir() + "/data.h3";
FileUtils.delete(fileName); FileUtils.delete(fileName);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论