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