提交 775b1b00 authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent tree map (work in progress)

上级 4c584cef
......@@ -701,7 +701,8 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
new TestTools().runTest(this);
new TestTreeMapStore().runTest(this);
int test;
// new TestTreeMapStore().runTest(this);
new TestTraceSystem().runTest(this);
new TestUpgrade().runTest(this);
new TestUtils().runTest(this);
......
......@@ -29,6 +29,7 @@ public class TestTreeMapStore extends TestBase {
}
public void test() throws Exception {
// testDefragment();
testReuseSpace();
testRandom();
testKeyValueClasses();
......@@ -36,6 +37,30 @@ public class TestTreeMapStore extends TestBase {
testSimple();
}
private void testDefragment() {
String fileName = getBaseDir() + "/data.h3";
FileUtils.delete(fileName);
long initialLength = 0;
for (int j = 0; j < 10; j++) {
TreeMapStore s = TreeMapStore.open(fileName);
StoredMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
for (int i = 0; i < 10; i++) {
m.put(j + i, "Hello " + j);
}
s.store();
System.out.println(s.toString());
s.compact();
s.close();
long len = FileUtils.size(fileName);
System.out.println(" len:" + len);
// if (initialLength == 0) {
// initialLength = len;
// } else {
// assertTrue(len <= initialLength * 2);
// }
}
}
private void testReuseSpace() {
String fileName = getBaseDir() + "/data.h3";
FileUtils.delete(fileName);
......
......@@ -43,6 +43,15 @@ public class StoredMap<K, V> {
}
}
static Class<?> getClass(String name) {
if (name.equals("i")) {
return Integer.class;
} else if (name.equals("s")) {
return String.class;
}
throw new RuntimeException("Unknown class name " + name);
}
static <K, V> StoredMap<K, V> open(TreeMapStore store, String name, Class<K> keyClass, Class<V> valueClass) {
return new StoredMap<K, V>(store, name, keyClass, valueClass);
}
......@@ -60,6 +69,10 @@ public class StoredMap<K, V> {
return (V) (n == null ? null : n.getData());
}
Node getNode(Object key) {
return Node.getNode(root, key);
}
public void remove(K key) {
if (!isChanged()) {
store.changed(name, this);
......@@ -78,6 +91,7 @@ public class StoredMap<K, V> {
int length(Object obj);
void write(ByteBuffer buff, Object x);
Object read(ByteBuffer buff);
String getName();
}
/**
......@@ -112,6 +126,10 @@ public class StoredMap<K, V> {
TreeMapStore.writeVarInt(buff, (Integer) x);
}
public String getName() {
return "i";
}
}
/**
......@@ -153,6 +171,10 @@ public class StoredMap<K, V> {
}
}
public String getName() {
return "s";
}
}
KeyType getKeyType() {
......@@ -183,7 +205,6 @@ public class StoredMap<K, V> {
root = readNode(rootPos);
}
public Iterator<K> keyIterator(K from) {
return new Cursor(root, from);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论