提交 30582d72 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: convert an empty root node to a leaf

上级 16c90bc4
......@@ -554,6 +554,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
Page p = copyOnWrite(root, v);
@SuppressWarnings("unchecked")
V result = (V) remove(p, v, key);
if (!p.isLeaf() && p.getTotalCount() == 0) {
p.removePage();
p = Page.createEmpty(this, p.getVersion());
}
newRoot(p);
return result;
} finally {
......@@ -682,7 +686,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
if (p.getKeyCount() == 0) {
p.setChild(index, c);
p.setCounts(index, c);
p.removePage();
c.removePage();
} else {
p.remove(index);
}
......@@ -1006,8 +1010,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
@Override
public boolean isEmpty() {
// could also use (sizeAsLong() == 0)
checkOpen();
return 0 == (root.isLeaf() ? root.getKeyCount() : root.getChildPageCount());
return root.isLeaf() && root.getKeyCount() == 0;
}
public long getCreateVersion() {
......
......@@ -77,6 +77,10 @@ public class MVMapConcurrent<K, V> extends MVMap<K, V> {
synchronized (this) {
Page p = copyOnWrite(root, v);
result = (V) remove(p, v, key);
if (!p.isLeaf() && p.getTotalCount() == 0) {
p.removePage();
p = Page.createEmpty(this, p.getVersion());
}
newRoot(p);
}
return result;
......
......@@ -155,9 +155,6 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
if (keyType.equals(p.getKey(i), key)) {
result = p.getValue(i);
p.remove(i);
if (p.getKeyCount() == 0) {
p.removePage();
}
break;
}
}
......@@ -181,7 +178,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
// this child was deleted
p.remove(i);
if (p.getKeyCount() == 0) {
p.removePage();
c.removePage();
}
break;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论