本文整理汇总了C++中LeafNode::maxPsize方法的典型用法代码示例。如果您正苦于以下问题:C++ LeafNode::maxPsize方法的具体用法?C++ LeafNode::maxPsize怎么用?C++ LeafNode::maxPsize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LeafNode
的用法示例。
在下文中一共展示了LeafNode::maxPsize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isLow
void InnerNode::isLow( Node *that )
{
// the child node THAT is <= half full. We will either redistribute
// elements between children, or THAT will be merged with another child.
// In an attempt to minimize the number of mergers, we adopt the following
// strategy:
// * redistribute if possible
// * if not possible, then merge with a sibling
if( that->isLeaf )
{
LeafNode *leaf = (LeafNode *)that;
LeafNode *left, *right;
// split LEAF only if both sibling nodes are full.
int leafidx = indexOf(leaf);
int hasRightSib = (leafidx < last)
&& ((right=(LeafNode*)getTree(leafidx+1))
!= 0);
int hasLeftSib = (leafidx > 0)
&& ((left=(LeafNode*)getTree(leafidx-1))
!= 0);
if( hasRightSib
&& (leaf->Psize() + right->Vsize()) >= leaf->maxPsize())
{
// then cannot merge,
// and balancing this and rightsib will leave them both
// more than half full
leaf->balanceWith( right, leafidx+1 );
}
else if( hasLeftSib
&& (leaf->Vsize() + left->Psize()) >= leaf->maxPsize())
{
// ditto
left->balanceWith( leaf, leafidx );
}
else if( hasLeftSib )
{
// then they should be merged
left->mergeWithRight( leaf, leafidx );
}
else if( hasRightSib )
{
leaf->mergeWithRight( right, leafidx+1 );
}
else
{
CHECK(0); // should never happen
}
}
else
{
InnerNode *inner = (InnerNode *)that;
//
int inneridx = indexOf(inner);
InnerNode *left, *right;
int hasRightSib = (inneridx < last)
&& ((right=(InnerNode*)getTree(inneridx+1))
!= 0);
int hasLeftSib = (inneridx > 0)
&& ((left=(InnerNode*)getTree(inneridx-1))
!= 0);
if( hasRightSib
&& (inner->Psize() + right->Vsize()) >= inner->maxPsize())
{
// cannot merge
inner->balanceWith( right, inneridx+1 );
}
else if( hasLeftSib
&& (inner->Vsize() + left->Psize()) >= inner->maxPsize())
{
// cannot merge
left->balanceWith( inner, inneridx );
}
else if( hasLeftSib )
{
left->mergeWithRight( inner, inneridx );
}
else if( hasRightSib )
{
inner->mergeWithRight( right, inneridx+1 );
}
else
{
CHECK(0);
}
}
}