void LeafNode::mergeNode(FatherNode* parentNode, FatherNode* childNode, int keyIndex) { for (int i = 0; i < childNode->getKeyNum(); ++i) { insert(childNode->getKeyValue(i), ((LeafNode*)childNode)->getData(i)); } setRightSibling(((LeafNode*)childNode)->getRightSibling()); parentNode->removeKey(keyIndex, keyIndex + 1); }
void CLeafNode::mergeChild(CNode* parentNode, CNode* childNode, int keyIndex) { // 合并数据 for (int i=0; i<childNode->getKeyNum(); ++i) { insert(childNode->getKeyValue(i), ((CLeafNode*)childNode)->getData(i)); } setRightSibling(((CLeafNode*)childNode)->getRightSibling()); //父节点删除index的key, parentNode->removeKey(keyIndex, keyIndex+1); }
void LeafNode::splitNode(FatherNode* parentNode, int childIndex) { LeafNode* newNode = new LeafNode(); setKeyNum(MIN_LEAF); newNode->setKeyNum(MIN_LEAF + 1); newNode->setRightSibling(getRightSibling()); setRightSibling(newNode); newNode->setLeftSibling(this); int i; for (i = 0; i < MIN_LEAF + 1; ++i) { newNode->setKeyValue(i, m_KeyValues[i + MIN_LEAF]); } for (i = 0; i < MIN_LEAF + 1; ++i) { newNode->setData(i, m_Datas[i + MIN_LEAF]); } ((InternalNode*)parentNode)->insert(childIndex, childIndex + 1, m_KeyValues[MIN_LEAF], newNode); }
void CLeafNode::split(CNode* parentNode, int childIndex) { CLeafNode* newNode = new CLeafNode();//分裂后的右节点 setKeyNum(MINNUM_LEAF); newNode->setKeyNum(MINNUM_LEAF+1); newNode->setRightSibling(getRightSibling()); setRightSibling(newNode); newNode->setLeftSibling(this); int i; for (i=0; i<MINNUM_LEAF+1; ++i)// 拷贝关键字的值 { newNode->setKeyValue(i, m_KeyValues[i+MINNUM_LEAF]); } for (i=0; i<MINNUM_LEAF+1; ++i)// 拷贝数据 { newNode->setData(i, m_Datas[i+MINNUM_LEAF]); } ((CInternalNode*)parentNode)->insert(childIndex, childIndex+1, m_KeyValues[MINNUM_LEAF], newNode); }
/*叶子节点*/ LeafNode::LeafNode() :FatherNode() { setType(LEAF); setLeftSibling(NULL); setRightSibling(NULL); }
// CLeafNode CLeafNode::CLeafNode():CNode() { setType(LEAF); setLeftSibling(NULL); setRightSibling(NULL); }