提交 c81ea7f4 authored 作者: andrei's avatar andrei

fix DEFRAG

上级 9ca551f6
......@@ -1104,36 +1104,26 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/
final void copyFrom(MVMap<K, V> sourceMap) {
beforeWrite();
setRoot(copy(sourceMap.getRootPage(), null));
setRoot(copy(sourceMap.getRootPage()));
}
private Page copy(Page source, CursorPos parent) {
private Page copy(Page source) {
Page target = source.copy(this);
store.registerUnsavedPage(target.getMemory());
if (!source.isLeaf()) {
CursorPos pos = new CursorPos(target, 0, parent);
for (int i = 0; i < getChildPageCount(target); i++) {
if (source.getChildPagePos(i) != 0) {
// position 0 means no child
// (for example the last entry of an r-tree node)
// (the MVMap is also used for r-trees for compacting)
pos.index = i;
Page child = copy(source.getChildPage(i), pos);
Page child = copy(source.getChildPage(i));
target.setChild(i, child);
pos.page = target;
}
}
if(store.isSaveNeeded()) {
Page child = target;
for(CursorPos p = parent; p != null; p = p.parent) {
p.page.setChild(p.index, child);
child = p.page;
}
setRoot(child);
setRoot(target);
beforeWrite();
}
}
return target;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论