提交 82f38479 authored 作者: Andrei Tokar's avatar Andrei Tokar

backward compatibility path for #1952

上级 03c4ec3b
...@@ -1305,10 +1305,15 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1305,10 +1305,15 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private static Page replacePage(CursorPos path, Page replacement, IntValueHolder unsavedMemoryHolder) { private static Page replacePage(CursorPos path, Page replacement, IntValueHolder unsavedMemoryHolder) {
int unsavedMemory = replacement.getMemory(); int unsavedMemory = replacement.getMemory();
while (path != null) { while (path != null) {
Page child = replacement; Page parent = path.page;
replacement = path.page.copy(); // condition below sould always be true, but older versions (up to 1.4.197)
replacement.setChild(path.index, child); // may create single-childed (with no keys) internal nodes, which we skip here
unsavedMemory += replacement.getMemory(); if (parent.getKeyCount() > 0) {
Page child = replacement;
replacement = parent.copy();
replacement.setChild(path.index, child);
unsavedMemory += replacement.getMemory();
}
path = path.parent; path = path.parent;
} }
unsavedMemoryHolder.value += unsavedMemory; unsavedMemoryHolder.value += unsavedMemory;
...@@ -1706,15 +1711,27 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1706,15 +1711,27 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
if (p.getTotalCount() == 1 && pos != null) { if (p.getTotalCount() == 1 && pos != null) {
p = pos.page; int keyCount;
index = pos.index; do {
pos = pos.parent; p = pos.page;
if (p.getKeyCount() == 1) { index = pos.index;
assert index <= 1; pos = pos.parent;
p = p.getChildPage(1 - index); keyCount = p.getKeyCount();
// condition below sould always be false, but older versions (up to 1.4.197)
// may create single-childed (with no keys) internal nodes, which we skip here
} while (keyCount == 0 && pos != null);
if (keyCount <= 1) {
if (keyCount == 1) {
assert index <= 1;
p = p.getChildPage(1 - index);
} else {
// if root happens to be such single-childed (with no keys) internal node,
// then just replace it with empty leaf
p = Page.createEmptyLeaf(this);
}
break; break;
} }
assert p.getKeyCount() > 1;
} }
p = p.copy(); p = p.copy();
p.remove(index); p.remove(index);
...@@ -1864,7 +1881,6 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1864,7 +1881,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private static CursorPos traverseDown(Page p, Object key) { private static CursorPos traverseDown(Page p, Object key) {
CursorPos pos = null; CursorPos pos = null;
while (!p.isLeaf()) { while (!p.isLeaf()) {
assert p.getKeyCount() > 0;
int index = p.binarySearch(key) + 1; int index = p.binarySearch(key) + 1;
if (index < 0) { if (index < 0) {
index = -index; index = -index;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论