本文整理汇总了C++中LeafNode::balanceWithLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ LeafNode::balanceWithLeft方法的具体用法?C++ LeafNode::balanceWithLeft怎么用?C++ LeafNode::balanceWithLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LeafNode
的用法示例。
在下文中一共展示了LeafNode::balanceWithLeft方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isFull
void InnerNode::isFull(Node *that)
{
// the child node THAT is full. We will either redistribute elements
// or create a new node and then redistribute.
// In an attempt to minimize the number of splits, we adopt the following
// strategy:
// * redistribute if possible
// * if not possible, then split 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);
int rightSibFull = (hasRightSib && right->isAlmostFull());
int leftSibFull = (hasLeftSib && left->isAlmostFull());
if( rightSibFull )
{
if( leftSibFull )
{
// both full, so pick one to split with
left->splitWith( leaf, leafidx );
}
else if( hasLeftSib )
{
// left sib not full, so balance with it
leaf->balanceWithLeft( left, leafidx );
}
else
{
// there is no left sibling, so split with right
leaf->splitWith( right, leafidx+1 );
}
}
else if( hasRightSib )
{
// right sib not full, so balance with it
leaf->balanceWithRight( right, leafidx+1 );
}
else if( leftSibFull )
{
// no right sib, and left sib is full, so split with it
left->splitWith( leaf, leafidx );
}
else if( hasLeftSib )
{
// left sib not full so balance with it
leaf->balanceWithLeft( left, leafidx );
}
else
{
// neither a left or right sib; should never happen
CHECK(0);
}
}
else {
InnerNode *inner = (InnerNode *)that;
// split INNER only if both sibling nodes are full.
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);
int rightSibFull = (hasRightSib && right->isAlmostFull());
int leftSibFull = (hasLeftSib && left->isAlmostFull());
if( rightSibFull )
{
if( leftSibFull )
{
left->splitWith( inner, inneridx );
}
else if( hasLeftSib )
{
inner->balanceWithLeft( left, inneridx );
}
else
{
// there is no left sibling
inner->splitWith(right, inneridx+1);
}
}
else if( hasRightSib )
{
inner->balanceWithRight( right, inneridx+1 );
}
else if( leftSibFull )
{
left->splitWith( inner, inneridx );
}
else if( hasLeftSib )
{
//.........这里部分代码省略.........