当前位置: 首页>>代码示例>>C++>>正文


C++ BTreeNode::addChild方法代码示例

本文整理汇总了C++中BTreeNode::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ BTreeNode::addChild方法的具体用法?C++ BTreeNode::addChild怎么用?C++ BTreeNode::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BTreeNode的用法示例。


在下文中一共展示了BTreeNode::addChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addToNode

void BTree::addToNode(BTreeNode *node, BTreeElement *child) {
	if (!node->addChild(child->getMinId(), child)) {
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Node is full");
		BTreeNode *newNode = new BTreeNode(this, nodeCapacity);
		int oldMinId = node->getMinId();
		node->split(newNode);

		BTreeNode *addTo;
		if (node->getMinId() == -1 || child->getMinId() > node->getMinId())
			addTo = node;
		else
			addTo = newNode;

		if (!addTo->addChild(child->getMinId(), child)) {
		//	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Node add FAILED!");
			return;
		}

		if (node->getParent() == NULL) {
		//	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "This node's parent is null");
			BTreeNode *parent = new BTreeNode(this, nodeCapacity);
			parent->addChild(node->getMinId(), node);
			root = parent;
		}
		addToNode(node->getParent(), newNode);
	}
	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Added new node to parent");
}
开发者ID:tomahawkpl,项目名称:Jello,代码行数:28,代码来源:BTree.cpp

示例2: test_save_open_node

void test_save_open_node() {
    BTreeFS fs("test_btree_fs.dat", 4);
    BTreeNode node = fs.allocNode(true);
    node.setSentinel(rand());
    node.setKeysNum(4);
    node.addChild(23, rand());
    node.addChild(48, rand());
    node.addChild(236, rand());
    node.addChild(326, rand());
    fs.saveNode(node);
    BTreeNode saved_node = fs.openNode(node.ref());
    assert(node == saved_node);
}
开发者ID:k1nkreet,项目名称:btree,代码行数:13,代码来源:test_btree_fs.cpp

示例3: add

void BTree::add(int id, RecordInfo *record) {
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "== BTree add id: %d", id);
	if (root == NULL) {
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "new leaf as root: %d", leafCapacity);
		root = new BTreeLeaf(this, leafCapacity);
	}

	BTreeElement *e = root;

	while (e->type == BTreeElement::ELEMENT_NODE) {
		e = ((BTreeNode*)e)->getSubNodeFor(id);
		if (e == NULL)
			return;
	}

	BTreeLeaf *leaf = (BTreeLeaf*)e;

	if (!leaf->add(id, record)) {
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Not enough space in leaf");
		BTreeLeaf *newLeaf = new BTreeLeaf(this, leafCapacity);

		int oldMinId = leaf->getMinId();
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Splitting");
		leaf->split(newLeaf);
		BTreeLeaf *addTo;
		if (leaf->getMinId() == -1 || id > leaf->getMinId())
			addTo = leaf;
		else
			addTo = newLeaf;

		if (!addTo->add(id, record)) {
			//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Leaf add FAILED!");
			return;
		}

		if (leaf->getParent() == NULL) {
			//__android_log_print(ANDROID_LOG_INFO, "Jello",  "This leaf's parent is NULL, creating new node");
			BTreeNode *node = new BTreeNode(this, nodeCapacity);
			node->addChild(leaf->getMinId(), leaf);
			root = node;
		}

		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Adding new node to parent");
		addToNode(leaf->getParent(), newLeaf);
	}

}
开发者ID:tomahawkpl,项目名称:Jello,代码行数:47,代码来源:BTree.cpp

示例4: update

void BTree::update(int id, RecordInfo *record) {
	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Update: %d", id);
	BTreeElement *e = root;

	if (e == NULL)
		return;

	while (e->type == BTreeElement::ELEMENT_NODE) {
		e = ((BTreeNode*)e)->getSubNodeFor(id);
		if (e == NULL)
			return;
	}

	BTreeLeaf *leaf = (BTreeLeaf*)e;

	if (!leaf->update(id, record)) {
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "update failed, splitting node");
		BTreeLeaf *newLeaf = new BTreeLeaf(this, leafCapacity);
		int oldMinId = leaf->getMinId();
		leaf->split(newLeaf);
		if (id < leaf->getMinId()) {
			if (!newLeaf->update(id, record)) {
				//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Leaf add FAILED!");
				return;
			}
		} else {
			if (!leaf->update(id, record)) {
				//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Leaf add FAILED!");
				return;
			}
		}

		if (leaf->getParent() == NULL) {
			BTreeNode *node = new BTreeNode(this, nodeCapacity);
			node->addChild(leaf->getMinId(), leaf);
		}

		addToNode(leaf->getParent(), newLeaf);
	} else
		mergeNode(leaf);

}
开发者ID:tomahawkpl,项目名称:Jello,代码行数:42,代码来源:BTree.cpp


注:本文中的BTreeNode::addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。