Exemple #1
0
static BSNode* initNode(int m, int key, void* value)
{
	BSNode* node = _initNode(m);
	node->keyNum = 1;
	node->keys[1] = key;
	node->values[1] = value;
	return node;
}
Exemple #2
0
static void splitNode(BSTree* tree, BSNode* node)
{
	int m = (int)ceil((float)node->keyNum / 2);
	int mKey = node->keys[m];
	void* mValue = node->values[m];
	BSNode* nNode = _initNode(tree->mOrder);
	int j = 0, i = 0;
	for(i = m + 1; i <= node->keyNum; ++i) {
		++j;
		nNode->keys[j] = node->keys[i];
		nNode->values[j] = node->values[i];
		nNode->children[j] = node->children[i];
		if (node->children[i])
			node->children[i]->parent = nNode;
		node->keys[i] = INT_MIN;
		node->values[i] = NULL;
		node->children[i] = NULL;
	}
	nNode->children[0] = node->children[m];
	if (nNode->children[0])
		nNode->children[0]->parent = nNode;
	nNode->keyNum  = j;

	node->keys[m] = INT_MIN;
	node->children[m] = NULL;
	node->values[m] = NULL;
	node->keyNum = m - 1;

	BSNode* p = node->parent;
	if (p) {
		insertKey(p, mKey, mValue, nNode);
		nNode->parent = p;
		if (p->keyNum > tree->mOrder -1)
			splitNode(tree, p);
	}
	else {
		BSNode* nNode2 = initNode(tree->mOrder, mKey, mValue);
		nNode2->children[0] = node;
		nNode2->children[1] = nNode;
		node->parent = nNode2;
		nNode->parent = nNode2;
		tree->root = nNode2;
	}
}
Exemple #3
0
Queue::Queue() {
    _initNode();
}