Exemplo n.º 1
0
void BPlusTree::splitParent(BTreeNode * node , int key , BTreeNode * leftNode , BTreeNode * rightNode)
{
		if(node == NULL)
			{
				root = new BTreeNode();
				root->getkeys().push_back(key);
				root->getChidNodes().push_back(leftNode);
				root->getChidNodes().push_back(rightNode);
				return;
			}
		node->insertIntoNode(key , leftNode , rightNode);
		int splitIndex = node->getkeys().size()/2;


		BTreeNode * left = node;
		BTreeNode * right = new BTreeNode();
		int keyToElevate = node->getkeys()[splitIndex];
		right->copyContent(left , splitIndex+1 , node->getkeys().size()-1);
		left->getkeys().resize(splitIndex);
		left->getChidNodes().resize(splitIndex);

		if(node->getparent() == NULL || node->getparent()->isFull())
			splitParent(node->getparent() ,keyToElevate, left , right );
		else
		{
			node->insertIntoNode(keyToElevate , left , right);
			left->setParent(node);
			right->setParent(node);
		}
		return;
}
Exemplo n.º 2
0
void BPlusTree::split(BTreeNode * node , int key , int value )
{
	// key should not be duplicate;
	// this method is only for leafnodes;
	int splitIndex = -1;
	node->InsertIntoLeafNode(key,value);
	splitIndex = node->getkeys().size()/2;
	BTreeNode * left = node;
	BTreeNode * right = new BTreeNode();
	right->setLeaf(true);
	int keyToElevate = node->getkeys()[splitIndex];
	right->copyContent(node , splitIndex +1 , node->getkeys().size()-1);
	node->getkeys().resize(splitIndex+1);
	if(node->getparent() == NULL )
	{
		root = new BTreeNode();
		root->getkeys().push_back(keyToElevate);
		root->getChidNodes().push_back(left);
		root->getChidNodes().push_back(right);
		left->setParent(root);
		right->setParent(root);
		return;
	}
	if(node->getparent()->isFull())
	{
		splitParent( node->getparent() , keyToElevate , left , right);
	}
	else
	{
		node->getparent()->insertIntoNode(keyToElevate , left , right);
	}
}