예제 #1
0
void Page::merge()
{
	bool ok = false;
	for (uint i = 0; i < child.size(); i++)
	{
		if (child[i] != NULL)
		{
			(child[i])->merge();
			Page* buff = child[i];
			if (buff->GetSize() < 2 * _t + 1 - GetSize())
			{
				child.erase(child.begin()+i);
				for (int j = buff->GetSize() - 1; j >= 0; j--)
				{
					keys.insert(keys.begin()+i, buff->GetKey(j));
					child.insert(child.begin()+i, buff->GetChildren(j + 1));
				}
				child.insert(child.begin()+i, buff->GetChildren(0));
				ok = true;
				for (uint k = 0; k < buff->keys.size()-1; k++)
				{
					buff->child.erase(child.begin());
					buff->keys.erase(keys.begin());
				}
				buff->child.erase(child.begin());
				break;
			}
			if (ok) break;
		}
	}
}