本文整理汇总了C++中InternalNode::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ InternalNode::insert方法的具体用法?C++ InternalNode::insert怎么用?C++ InternalNode::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InternalNode
的用法示例。
在下文中一共展示了InternalNode::insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
InternalNode* InternalNode::split(int value){
InternalNode* newNode = new InternalNode(internalSize, leafSize, parent, this, NULL);
sort();
BTreeNode* oldRightNode = getRightSibling();
if(oldRightNode){
oldRightNode->setLeftSibling(newNode);
newNode->setRightSibling(oldRightNode);
newNode->setLeftSibling(this);
}
//cout << keys[0] << " " << keys[1] << " " << keys[2] << endl;
//cout << children[0]->getMinimum() << " " << children[1]->getMinimum() << endl;
for(int i = ((internalSize+1) / 2); i < internalSize; i++){
//cout << "Internal: Inserting " << keys[i] << " into new Node" << endl;
newNode->insert(keys[i]);
}
count = count - newNode->getCount();
if(keys[0] > value){
newNode->insert(keys[0]);
keys[0] = value;
}
else{
newNode->insert(value);
}
setRightSibling(newNode);
return newNode;
}
示例2: split
InternalNode* InternalNode::split(BTreeNode* nodeCausingSplit)
{
int i;
//cout << "SPLIT : " << nodeCausingSplit << " : " << nodeCausingSplit->getMinimum() << endl;
InternalNode* newRight =
new InternalNode(internalSize, leafSize, this->parent, this, this->rightSibling);
/*(internalSize + 1) / 2 gives index of last value guaranteed to move to newRight
((internalSize + 1) / 2) - 1 gives the value that could go depending on if the
new value or the old value stored at that position in keys[] is larger */
for (i = internalSize - 1; i >= (internalSize + 1) / 2; i--)
{
newRight->insert(children[i]);
(children[i])->setParent(newRight);
}
if (nodeCausingSplit->getMinimum() > keys[((internalSize + 1) / 2) - 1] ) // given value is greater than middle position
{
nodeCausingSplit->setParent(newRight);
newRight->insert(nodeCausingSplit);
(children[i + 1])->setLeftSibling(nodeCausingSplit);
nodeCausingSplit->setRightSibling(children[i + 1]);
nodeCausingSplit->setLeftSibling(children[((internalSize + 1) / 2) - 1]);
(children[((internalSize + 1) / 2) - 1])->setRightSibling(nodeCausingSplit);
}
else
{
newRight->insert( children[((internalSize + 1) / 2) - 1] );
(children[((internalSize + 1) / 2) - 1])->setParent(newRight);
(children[i + 1])->setLeftSibling(children[((internalSize + 1) / 2) - 1]);
(children[((internalSize + 1) / 2) - 1])->setRightSibling(children[i + 1]);
(children[((internalSize + 1) / 2) - 1])->setLeftSibling(nodeCausingSplit);
nodeCausingSplit->setRightSibling(children[((internalSize + 1) / 2) - 1]);
children[((internalSize + 1) / 2) - 1] = nodeCausingSplit;
keys[((internalSize + 1) / 2) - 1] = nodeCausingSplit->getMinimum();
}
/*if (internalSize % 2 == 0)*/
count = ((internalSize + 1) / 2);
/*else
count = ((internalSize + 1) / 2) + 1;*/
if (rightSibling)
rightSibling->setLeftSibling(newRight);
rightSibling = newRight;
return newRight;
} // LeafNode::split()
示例3: insert
void BTree::insert(const int value)
{
BTreeNode *split = root->insert(value);
if (split) // LeafNode needs split
{
InternalNode *parent = new InternalNode(internalSize, leafSize, NULL,
NULL, NULL);
root->setParent(parent); // set parents to root
split->setParent(parent);
parent->insert(root); // should be on the left
parent->insert(split); // should be on the right
root = parent;
} // if split needed
} // BTree::insert()
示例4: insert
void BTree::insert(const int value)
{
BTreeNode *ptr = root->insert(value);
if(ptr) // root split
{
InternalNode *IPtr = new InternalNode(internalSize, leafSize,
NULL, NULL, NULL);
IPtr->insert(root, ptr);
root = IPtr;
} // if root split
} // BTree::insert()
示例5: insert
void BTree::insert(const int value)
{
//cout << "Root insert\n";
BTreeNode *ptr = root->insert(value);
if(ptr) //split
{
//cout << "[Root] Split\n";
InternalNode *nroot = new InternalNode (internalSize, leafSize, NULL, NULL, NULL);
nroot->insert(root,ptr);
root = nroot;
}
} // BTree::insert()
示例6: mergeLeft
void InternalNode::mergeLeft()
{
InternalNode * leftSib = (InternalNode *) getLeftSibling();
while(count != 0)
{
leftSib->insert(children[count-1]); //minimize shifting
removeDriver(count-1); //delete shifted value
}
InternalNode * rightSib = (InternalNode *) getRightSibling();
leftSib->rightSibling = rightSib;
if(rightSib != NULL)
rightSib->leftSibling = leftSib;
if(parent)
parent->resetMinimum(this);
} //InternalNode::mergeLeft()