亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? btreeinn.cpp

?? uc/os 很好的學習代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/*------------------------------------------------------------------------*/
/*                                                                        */
/*  BTREEINN.CPP                                                          */
/*                                                                        */
/*  Copyright Borland International 1991                                  */
/*  All Rights Reserved                                                   */
/*                                                                        */
/*------------------------------------------------------------------------*/

#if !defined( CHECKS_H )
#include <Checks.h>
#endif  // CHECKS_H

#if !defined( __BTREE_H )
#include <BTree.h>
#endif  // __BTREE_H

#ifndef __STDLIB_H
#include <stdlib.h>
#endif

#ifndef __IOSTREAM_H
#include <iostream.h>
#endif

//====== InnerNode functions ======

InnerNode::InnerNode(InnerNode* P, Btree* T) : Node(0,P,T)
{
    item = new Item[maxIndex()+1];
    if( item == 0 )
        ClassLib_error( __ENOMEMIA );
}

InnerNode::InnerNode(InnerNode* Parent, Btree* Tree, Node* oldroot)
                : Node(0, Parent, Tree)
{
    // called only by Btree to initialize the InnerNode that is
    // about to become the root.
    item = new Item[maxIndex()+1];
    if( item == 0 )
        ClassLib_error( __ENOMEMIA );
    append( 0, oldroot );
}

InnerNode::~InnerNode()
{
    if( last > 0 )
        delete item[0].tree;
    for( int i = 1; i <= last; i++ )
        {
        delete item[i].tree;
        if( tree->ownsElements() )
            delete item[i].key;
        }
    delete [] item;
}

// for quick (human reader) lookup, functions are in alphabetical order

void InnerNode::add( Sortable *obj, int index )
{
    // this is called only from Btree::add()
    PRECONDITION( index >= 1 );
    LeafNode* ln = getTree(index-1)->lastLeafNode();
    ln->add( obj, ln->last+1 );
}

void InnerNode::addElt( Item& itm, int at )
{
    PRECONDITION( 0 <= at && at <= last+1 );
    PRECONDITION( last < maxIndex() );
    for( int i = last+1; i > at ; i-- )
        getItem(i) = getItem(i-1);
    setItem( at, itm );
    last++;
}

void InnerNode::addElt( int at, Sortable* k, Node* t)
{
    Item newitem( k, t );
    addElt( newitem, at );
}

void InnerNode::add( Item& itm, int at )
{
    addElt( itm, at );
    if( isFull() )
        informParent();
}

void InnerNode::add( int at, Sortable* k, Node* t)
{
    Item newitem( k, t );
    add( newitem, at );
}

void InnerNode::appendFrom( InnerNode* src, int start, int stop )
{
    // this should never create a full node
    // that is, it is not used anywhere where THIS could possibly be
    // near full.
    if( start > stop )
        return;
    PRECONDITION( 0 <= start && start <= src->last );
    PRECONDITION( 0 <= stop  && stop  <= src->last );
    PRECONDITION( last + stop - start + 1 < maxIndex() ); // full-node check
    for( int i = start; i <= stop; i++ )
        setItem( ++last, src->getItem(i) );
}

void InnerNode::append( Sortable* D, Node* N )
{
    // never called from anywhere where it might fill up THIS
    PRECONDITION( last < maxIndex() );
    setItem( ++last, D, N );
}

void InnerNode::append( Item& itm )
{
    PRECONDITION( last < maxIndex() );
    setItem( ++last, itm );
}

void InnerNode::balanceWithLeft( InnerNode* leftsib, int pidx )
{
    // THIS has more than LEFTSIB;  move some item from THIS to LEFTSIB.
    // PIDX is the index of the parent item that will change when keys
    // are moved.
    PRECONDITION( Vsize() >= leftsib->Psize() );
    PRECONDITION( parent->getTree(pidx) == this );
    int newThisSize = (Vsize() + leftsib->Psize())/2;
    int noFromThis = Psize() - newThisSize;
    pushLeft( noFromThis, leftsib, pidx );
}

void InnerNode::balanceWithRight( InnerNode* rightsib, int pidx )
{
    // THIS has more than RIGHTSIB;  move some items from THIS to RIGHTSIB.
    // PIDX is the index of the parent item that will change when keys
    // are moved.
    PRECONDITION( Psize() >= rightsib->Vsize() );
    PRECONDITION( parent->getTree(pidx) == rightsib );
    int newThisSize = (Psize() + rightsib->Vsize())/2;
    int noFromThis = Psize() - newThisSize;
    pushRight( noFromThis, rightsib, pidx );

}

void InnerNode::balanceWith( InnerNode* rightsib, int pindx )
{
    // PINDX is the index of the parent item whose key will change when
    // keys are shifted from one InnerNode to the other.
    if( Psize() < rightsib->Vsize() )
        rightsib->balanceWithLeft( this, pindx );
    else
        balanceWithRight( rightsib, pindx );
}

void InnerNode::decrNofKeys( Node *that )
{
    // THAT is a child of THIS that has just shrunk by 1
    int i = indexOf( that );
    item[i].nofKeysInTree--;
    if( parent != 0 )
        parent->decrNofKeys( this );
    else
        tree->decrNofKeys();
}

long InnerNode::findRank( Sortable* what ) const
{
    // recursively look for WHAT starting in the current node

    if ( *what < *getKey(1) )
        return getTree(0)->findRank(what);
    long sum = getNofKeys(0);
    for( int i = 1; i < last; i++ )
        {
        if( *what == *getKey(i) )
            return sum;
        sum++;
        if( *what < *getKey(i+1) )
            return sum + getTree(i)->findRank(what);
        sum += getNofKeys(i);
        }
    if( *what == *getKey(last) )
        return sum;
    sum++;
    // *what > getKey(last), so recurse on last item.tree
    return sum + getTree(last)->findRank(what);
}

long InnerNode::findRank_bu( const Node *that ) const
{
    // findRank_bu is findRank in reverse.
    // whereas findRank looks for the object and computes the rank
    // along the way while walking DOWN the tree, findRank_bu already
    // knows where the object is and has to walk UP the tree from the
    // object to compute the rank.
    int L = indexOf( that );
    long sum = 0;
    for( int i = 0; i < L; i++ )
        sum += getNofKeys(i);
    return sum + L + (parent == 0 ? 0 : parent->findRank_bu( this ));
}

LeafNode*InnerNode::firstLeafNode()
{
    return getTree(0)->firstLeafNode();
}

Object& InnerNode::found(Sortable* what, Node** which, int* where )
{
    // recursively look for WHAT starting in the current node
    for( int i = 1 ; i <= last; i++ )
        {
        if( *getKey(i) == *what )
            {
            // then could go in either item[i].tree or item[i-1].tree
            // should go in one with the most room, but that's kinda
            // hard to calculate, so we'll stick it in item[i].tree
            *which = this;
            *where = i;
            return *getKey(i);
            }
        if( *getKey(i) > *what )
            return getTree(i-1)->found(what, which, where);
        }
    // *what > *(*this)[last].key, so recurse on last item.tree
    return getTree(last)->found( what, which, where );
}

void InnerNode::incrNofKeys( Node *that )
{
    // THAT is a child of THIS that has just grown by 1
    int i = indexOf( that );
    item[i].nofKeysInTree++;
    if( parent != 0 )
        parent->incrNofKeys( this );
    else
        tree->incrNofKeys();
}

#pragma warn -rvl

int InnerNode::indexOf( const Node *that ) const
{
    // returns a number in the range 0 to this->last
    // 0 is returned if THAT == tree[0]
    for( int i = 0; i <= last; i++ )
        if( getTree(i) == that )
            return i;
    CHECK( 0 );
}

#pragma warn .rvl

void InnerNode::informParent()
{
    if( parent == 0 )
        {
        // then this is the root of the tree and nees to be split
        // inform the btree.
        PRECONDITION( tree->root == this );
        tree->rootIsFull();
        }
    else
        parent->isFull( this );
}

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色婷婷av久久久久久久| 日韩欧美久久一区| 亚洲欧洲美洲综合色网| 成人免费电影视频| 久久久精品天堂| av电影在线观看不卡| 亚洲精品免费播放| 欧美精品乱码久久久久久按摩| 亚洲自拍偷拍欧美| 欧美伦理电影网| 精品一区二区三区日韩| 久久尤物电影视频在线观看| 国产.精品.日韩.另类.中文.在线.播放| 精品久久久久久综合日本欧美| 粉嫩绯色av一区二区在线观看| 中文字幕一区免费在线观看| 在线观看亚洲专区| 美女视频黄 久久| 亚洲国产精品国自产拍av| 色视频成人在线观看免| 琪琪久久久久日韩精品| 国产亚洲1区2区3区| 欧美一级专区免费大片| 国产99久久久国产精品潘金| 亚洲精品一二三四区| 日韩一区二区在线看| 国产精品一区在线| 亚洲图片一区二区| 久久这里只精品最新地址| 色屁屁一区二区| 国产乱码精品一区二区三区av| 亚洲美女视频在线| 欧美videos中文字幕| 日本精品裸体写真集在线观看| 美国av一区二区| 亚洲天堂av一区| 久久亚洲春色中文字幕久久久| 色综合色综合色综合| 国产成人综合精品三级| 日本成人超碰在线观看| 亚洲少妇30p| 久久久久免费观看| 欧美一区二区三区系列电影| 国产成人av一区二区| 视频在线观看91| 国产精品久久久久aaaa| 日韩欧美一二三四区| 欧美最猛黑人xxxxx猛交| 风流少妇一区二区| 狠狠色狠狠色合久久伊人| 亚洲成人免费在线观看| 午夜精品成人在线| 亚洲日本青草视频在线怡红院 | 丝袜亚洲另类丝袜在线| 国产精品色眯眯| 欧美精品一区二区不卡| 欧美一区二区视频在线观看2020| 色噜噜夜夜夜综合网| 成人小视频在线| 国产高清不卡二三区| 奇米综合一区二区三区精品视频| 亚洲国产精品一区二区尤物区| 亚洲国产经典视频| 久久久无码精品亚洲日韩按摩| 欧美一级欧美三级| 欧美久久久久久蜜桃| 欧美少妇性性性| 在线观看不卡视频| 一本色道久久综合亚洲精品按摩| av在线播放不卡| 99re热视频精品| 9人人澡人人爽人人精品| 波多野结衣欧美| 成人国产精品视频| av福利精品导航| 3d动漫精品啪啪1区2区免费| 91色乱码一区二区三区| 99精品1区2区| 91麻豆精东视频| 色婷婷香蕉在线一区二区| 欧美在线免费观看视频| 欧美老年两性高潮| 欧美一区二区三区免费观看视频 | 欧美日韩和欧美的一区二区| 在线观看一区二区精品视频| 欧美伊人精品成人久久综合97| 欧日韩精品视频| 欧美一区二区在线免费播放| 欧美一区二区久久久| 精品国产精品一区二区夜夜嗨| 久久综合av免费| 亚洲欧洲国产日本综合| 一区二区日韩电影| 日韩激情视频在线观看| 久久99深爱久久99精品| 国产成人av一区| 精品国产区一区| 久久婷婷色综合| 国产精品久久久久精k8| 亚洲一区二区三区在线看| 日韩福利视频导航| 懂色av一区二区三区免费观看 | 欧美精品一二三| 久久综合九色综合欧美就去吻| 亚洲国产电影在线观看| 一个色在线综合| 久久99精品国产.久久久久| 成人自拍视频在线| 欧美图片一区二区三区| www欧美成人18+| 亚洲美女精品一区| 九色|91porny| 一本到不卡免费一区二区| 日韩欧美第一区| 亚洲欧洲日本在线| 免费在线观看日韩欧美| 成人爱爱电影网址| 欧美精品vⅰdeose4hd| 亚洲亚洲精品在线观看| 天堂影院一区二区| 国产精品18久久久久久久网站| 欧美亚洲动漫另类| 久久久不卡网国产精品二区| 亚洲午夜影视影院在线观看| 国产毛片精品国产一区二区三区| 色综合天天综合色综合av | 中文字幕亚洲综合久久菠萝蜜| 亚洲国产精品精华液网站 | 色婷婷亚洲一区二区三区| 欧美成人一级视频| 亚洲午夜久久久| www.欧美日韩国产在线| 精品精品欲导航| 香蕉成人啪国产精品视频综合网 | 99久久99久久综合| 久久嫩草精品久久久精品| 日韩国产欧美三级| 色8久久精品久久久久久蜜| 亚洲自拍偷拍av| 丁香婷婷综合网| 精品久久久久久综合日本欧美| 亚洲国产综合色| 一本久道久久综合中文字幕| 国产精品网站导航| 国产一区二区在线视频| 91精品婷婷国产综合久久性色| **欧美大码日韩| 国产+成+人+亚洲欧洲自线| 精品噜噜噜噜久久久久久久久试看| 亚洲1区2区3区4区| 91搞黄在线观看| 亚洲免费在线看| 99精品在线观看视频| 久久久亚洲精品一区二区三区| 日本麻豆一区二区三区视频| 欧美日韩国产乱码电影| 亚洲一区在线观看免费观看电影高清| 成人永久aaa| 国产午夜三级一区二区三| 国产一区二区三区国产| 精品国产伦一区二区三区观看体验 | 成人黄色综合网站| 久久久久99精品一区| 国产一区二区三区免费看| 日韩一区二区免费电影| 蜜桃av一区二区| 精品久久久久久无| 狠狠网亚洲精品| 久久青草欧美一区二区三区| 国产综合成人久久大片91| 久久人人超碰精品| 成人黄色小视频在线观看| 日本一二三四高清不卡| 成a人片亚洲日本久久| 亚洲视频在线一区| 日本高清成人免费播放| 亚洲一区国产视频| 欧美日韩国产片| 久久99国产精品尤物| 欧美激情在线观看视频免费| 99久久99久久精品免费看蜜桃| 亚洲欧洲av在线| 欧美色图一区二区三区| 日韩在线卡一卡二| 精品国产成人在线影院| 国产成人精品aa毛片| 综合久久一区二区三区| 欧美日韩一卡二卡| 美日韩黄色大片| 亚洲成人一二三| 日韩一级完整毛片| 国产精品一区二区视频| 《视频一区视频二区| 欧美日韩国产在线观看| 美国十次了思思久久精品导航| 久久精品免费在线观看| 99re这里都是精品| 日韩在线观看一区二区| 久久精品人人做人人爽97| 欧美午夜不卡视频|