private VarKeyNode balanceChild(VarKeyInteriorNode leftNode, VarKeyInteriorNode rightNode)
			throws IOException {

		int leftKeyCount = leftNode.keyCount;
		int rightKeyCount = rightNode.keyCount;

		int len = buffer.length();
		int leftKeySpace = len - leftNode.getKeyOffset(leftKeyCount - 1);
		int rightKeySpace = len - rightNode.getKeyOffset(rightKeyCount - 1);
		Field rightKey = rightNode.getKeyField(0);

		// Can right keys fit within left node
		if ((rightKeySpace + (rightKeyCount * ENTRY_SIZE)) <= (len - BASE - leftKeySpace -
			(leftKeyCount * ENTRY_SIZE))) {
			// Right node is elliminated and all entries stored in left node
			moveKeysLeft(leftNode, rightNode, rightKeyCount);
			nodeMgr.deleteNode(rightNode);
			return deleteChild(rightKey);
		}

		boolean balanced = false;
		int halfKeySpace = (leftKeySpace + rightKeySpace) / 2;
		if (halfKeySpace < leftKeySpace) {
			// Attempt to move some keys to the right node
			int index = leftNode.getOffsetIndex(len - halfKeySpace);
			balanced = moveKeysRight(leftNode, rightNode, leftKeyCount - index - 1);
		}
		else {
			// Attempt to move some keys to the left node
			int index = rightNode.getOffsetIndex(len - halfKeySpace);
			balanced = moveKeysLeft(leftNode, rightNode, rightKeyCount - index - 1);
		}
		if (balanced) {
			this.keyChanged(rightKey, rightNode.getKeyField(0), rightNode);
		}
		return getRoot();
	}
Balance the entries contained within two adjacent child interior nodes.
One of the two nodes must be half-full or less.
This could result in the removal of a child node if entries will fit within
one node.
@param leftNode left child interior node
@param rightNode right child interior node
@return new root
@throws IOException thrown if an IO error occurs
Ghidra/Framework/DB/src/main/java/db/VarKeyInteriorNode.java