本文整理汇总了C++中BTreeNode::max方法的典型用法代码示例。如果您正苦于以下问题:C++ BTreeNode::max方法的具体用法?C++ BTreeNode::max怎么用?C++ BTreeNode::max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTreeNode
的用法示例。
在下文中一共展示了BTreeNode::max方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert
void BPlusTree::insert(DataType val) {
if (!root) {
root = new BTreeNode();
}
// searching a place for insert
BTreeNode *tp = root;
bool f = true;
while (!tp->isLeaf) {
f = false;
for(ListNode* lp = tp->children.begin(); lp; lp = lp->next) {
if (lp->index > val) {
tp = lp->child;
f = true;
break;
}
}
if (!f) {
// right node (max)
while (!tp->isLeaf) {
tp = tp->children.end()->child;
}
}
}
if(!f) {
//fixing delegates
int tmp = tp->max();
ListNode *d = tp->parent->children.find( tp->max() );
tp->children.insert(val);
while (d && d->child->parent && d->index == d->child->parent->max()) {
d->index = val;
d = d->child->parent->children.find( tmp );
}
} else {
tp->children.insert(val);
}
// if D keys are in this Node then split Node
if (tp->children.getLength() >= D) {
split(tp);
}
}
示例2: split
void BPlusTree::split(BTreeNode* node) {
DataType m = node->max();
// new right Node
BTreeNode *bro = new BTreeNode();
bro->parent = node->parent;
bro->lbro = node;
bro->rbro = node->rbro;
bro->isLeaf = node->isLeaf;
node->rbro = bro;
// splitting
ListNode *lp = node->children.begin();
int len1 = node->keysCount()/2;
int len2 = node->keysCount() - len1;
for(int i = 0; i < len1; i++) {
lp = lp->next;
}
node->children.setLength( len1 );
bro->children.setLength( len2 );
bro->children.setBegin( lp );
bro->children.setEnd( node->children.end() );
node->children.setEnd( lp->prev );
lp->prev->next = nullptr;
lp->prev = nullptr;
// fixing of delegates
if (node == root) {
BTreeNode *tp = new BTreeNode();
tp->isLeaf = false;
tp->children.insert( node->max(), node );
tp->children.insert( bro->max(), bro );
root = tp;
node->parent = root;
bro->parent = root;
} else {
ListNode *par = node->parent->children.find( m );
par->child = bro;
node->parent->children.insert( node->max(), node );
}
}