b树节点分割技术
B-Tree Node Splitting Techniques
我在做我的DSA(数据结构和算法)作业时偶然发现了一个问题。我说要实现一个带有插入和搜索算法的b树。到目前为止,搜索工作正常,但我在实现插入函数时遇到了麻烦。特别是b树节点分割算法背后的逻辑。我能想到的伪代码/c风格如下:
#define D 2
#define DD 2*D
typedef btreenode* btree;
typedef struct node
{
int keys[DD]; //D == 2 and DD == 2*D;
btree pointers[DD+1];
int index; //used to iterate throught the "keys" array
}btreenode;
void splitNode(btree* parent, btree* child1, btree* child2)
{
//Copies the content from the splitted node to the children
(*child1)->key[0] = (*parent)->key[0];
(*child1)->key[1] = (*parent)->key[1];
(*child2)->key[0] = (*parent)->key[2];
(*child2)->key[1] = (*parent)->key[3];
(*child1)->index = 1;
(*child2)->index = 1;
//"Clears" the parent node from any data
for(int i = 0; i<DD; i++) (*parent)->key[i] = -1;
for(int i = 0; i<DD+1; i++) (*parent)->pointers[i] = NULL
//Fixed the pointers to the children
(*parent)->index = 0;
//the line bellow was taken out for creating a new node that didn't have to be there.
//(*parent)->key[(*parent)->index] = newNode(); // The newNode() function allocs and inserts a the new key that I need to insert.
(*parent)->pointers[index] = (*child1);
(*parent)->pointers[index+1] = (*child2);
}
我几乎可以肯定我在指针上搞砸了什么,但我不确定是什么。任何帮助都是感激的。也许我需要在b树这门课上多学一点?我必须补充一点,虽然我可以使用c++的基本输入/输出,但我需要使用C风格的结构体。
您不需要在这里创建新节点。显然,您已经创建了两个新的子节点。在填充子节点之后,你所要做的就是让父节点指向两个子节点,通过复制每个子节点的第一个键,并将它的键数调整为2。您也不需要将父键设置为-1。
相关文章:
- 如何在C++中从字符串中分割字符
- C++映射分割错误(核心转储)
- C++为线程工作动态地分割例程
- 由cin中的字符串中未捕获空白引起的分割错误
- 在C++中样板"冷/never_inline"错误处理技术的最佳方法是什么?
- 删除映射和分割错误中的一个过去结束元素
- 在 Windows 8/10 技术中完全实时的屏幕捕获,没有延迟
- 在指向函数中读取变量时出现分割错误
- C++ 关于指针取消引用的技术问题
- 是否有技术原因阻止 Java 中的 final C++ 像 const 一样严格?
- 在链表中的第 n 位插入显示分割错误
- 较高值 n 的分割错误(例如 n=999997)
- 如何在 SEAL 3.1 中使用 CRT 批处理技术Microsoft?
- 暴力破解技术解决以下问题
- 是否可以制作没有内部分割的cgal 3d多多马因网格?
- 尝试通过memcpy复制大尺寸浮点向量时的分割错误
- std::complex<> in C++ 数学特殊函数:技术规范或提案
- 分割错误:向量中的擦除功能
- 向量向量的分割错误
- b树节点分割技术