in environment/src/main/java/jetbrains/exodus/tree/btree/LeafNode.java [120:174]
protected void reclaim(@NotNull final BTreeReclaimTraverser context) {
final ByteIterable keyIterable = getKey();
if (!context.canMoveDown() && context.canMoveRight()) {
final int leafIndex;
final int cmp = context.compareCurrent(keyIterable);
if (cmp > 0) {
return;
}
if (cmp == 0) {
leafIndex = context.currentPos;
} else {
context.moveRight();
leafIndex = context.getNextSibling(keyIterable, loggable.getAddress());
}
if (leafIndex >= 0) {
doReclaim(context, leafIndex);
context.moveTo(leafIndex + 1);
return;
} else if (context.canMoveTo(-leafIndex - 1)) {
return;
}
}
// go up
if (context.canMoveUp()) {
while (true) {
context.popAndMutate();
context.moveRight();
final int index = context.getNextSibling(keyIterable);
if (index < 0) {
if (context.canMoveTo(-index - 1) || !context.canMoveUp()) {
context.moveTo(Math.max(-index - 2, 0));
break;
}
} else {
context.pushChild(index); // node is always internal
break;
}
}
}
// go down
while (context.canMoveDown()) {
int index = context.getNextSibling(keyIterable);
if (index < 0) {
index = Math.max(-index - 2, 0);
}
context.pushChild(index);
}
int leafIndex = context.getNextSibling(keyIterable);
if (leafIndex >= 0) {
doReclaim(context, leafIndex);
context.moveTo(leafIndex + 1);
} else {
context.moveTo(-leafIndex - 1);
}
}