public void split(Node thisNode) // split the node
{
// assumes node is full
DataItem itemB, itemC; //数据项B,C
Node parent, child2, child3;//thisNode节点父节点,第3、4个子节点
int itemIndex;
itemC = thisNode.removeItem(); // 数据项C从thisNode节点移除
itemB = thisNode.removeItem(); // 数据项B从thisNode节点移除
child2 = thisNode.disconnectChild(2); // 节点的第3个子节点从节点中断开
child3 = thisNode.disconnectChild(3); //节点的第4个子节点从节点中断开
Node newRight = new Node(); // make new node
if(thisNode==root) // 如果是根节点,创建新的节点,作为根。它是要分裂节点的父节点。
{
root = new Node(); // make new root
parent = root; // root is our parent
root.connectChild(0, thisNode); // connect to parent
}
else // this node not the root
parent = thisNode.getParent(); // 得到节点的父节点
// deal with parent
itemIndex = parent.insertItem(itemB); // 将数据项B插入父节点,并返回插入的位置
int n = parent.getNumItems(); // 父节点的数据项总数
/*
*将父节点中子节点移动到合适的位置
*/
for(int j=n-1; j>itemIndex; j--) // move parent's
{ // connections
Node temp = parent.disconnectChild(j); // one child
parent.connectChild(j+1, temp); // to the right
}
// connect newRight to parent
parent.connectChild(itemIndex+1, newRight);//新节点与父节点相连
// deal with newRight
newRight.insertItem(itemC); // item C to newRight
newRight.connectChild(0, child2); // connect to 0 and 1
newRight.connectChild(1, child3); // on newRight
} // end split()