本文整理汇总了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");
}
示例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);
}
示例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);
}
}
示例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);
}