亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美成人猛片aaaaaaa| 国产精品久久久久久久久久免费看 | 久久精品综合网| 国产精品剧情在线亚洲| 亚洲午夜视频在线观看| 麻豆精品在线看| 国产成人av在线影院| 91麻豆精品一区二区三区| 精品视频一区二区三区免费| 日韩欧美一级在线播放| 亚洲国产精华液网站w| 亚洲电影一区二区三区| 精品一区二区三区日韩| 91在线国内视频| 日韩欧美一区二区不卡| 日韩美女精品在线| 毛片av一区二区| 日本丰满少妇一区二区三区| 精品少妇一区二区三区在线播放 | 亚洲国产欧美日韩另类综合 | 日韩午夜激情电影| 中文字幕中文字幕一区二区 | 欧美mv日韩mv| 亚洲香肠在线观看| 国产盗摄精品一区二区三区在线| 在线精品视频免费观看| 国产亚洲1区2区3区| 午夜精品视频一区| 99久久er热在这里只有精品15| 欧美一级日韩免费不卡| 亚洲人成7777| 国产河南妇女毛片精品久久久| 欧美性大战久久| 亚洲人成影院在线观看| 国产一区二区福利视频| 欧美嫩在线观看| 樱桃国产成人精品视频| 丁香啪啪综合成人亚洲小说| 亚洲精品在线免费观看视频| 舔着乳尖日韩一区| 在线视频你懂得一区| 国产精品美女久久久久久| 国产一区二三区| 欧美一卡二卡在线| 日韩电影在线一区二区三区| 在线观看国产精品网站| 亚洲免费高清视频在线| 波波电影院一区二区三区| 国产欧美综合在线| 五月天一区二区| 欧美日韩国产美女| 亚洲资源中文字幕| 欧美伊人精品成人久久综合97 | 欧美男生操女生| 亚洲va欧美va人人爽| 在线免费不卡视频| 亚洲福利视频一区| 欧美日韩亚洲不卡| 亚洲成人综合网站| 在线成人高清不卡| 免费人成在线不卡| 日韩欧美在线网站| 色呦呦一区二区三区| 国产精品麻豆99久久久久久| 成人app在线| 自拍偷拍亚洲综合| 在线观看亚洲精品视频| 亚洲精品福利视频网站| 欧美亚男人的天堂| 同产精品九九九| 精品日韩在线一区| 国产sm精品调教视频网站| 18成人在线观看| 91行情网站电视在线观看高清版| 亚洲福利一区二区三区| 日韩欧美色电影| 高清av一区二区| 亚洲精品免费看| 欧美一级日韩一级| 懂色av一区二区夜夜嗨| 亚洲另类中文字| 91精品国产综合久久蜜臀| 国产一区二区在线电影| 国产精品二三区| 欧美一区二区福利视频| 成人手机电影网| 亚洲福利一区二区| 国产无一区二区| 欧美色爱综合网| 国产成人高清视频| 国产欧美日韩亚州综合| 欧美日韩一区二区欧美激情| 国产一区二区三区观看| 一区二区三区在线影院| 精品少妇一区二区三区在线视频| 成人av资源网站| 日韩av一区二区在线影视| 中文字幕av一区二区三区| 欧美日韩一区不卡| 成人福利电影精品一区二区在线观看| 一区二区理论电影在线观看| 久久亚洲综合色一区二区三区| 色一区在线观看| 国产精品996| 日韩精品免费视频人成| 综合久久国产九一剧情麻豆| 精品蜜桃在线看| 不卡视频一二三| 日韩电影免费在线看| 国产精品免费视频一区| 制服丝袜中文字幕亚洲| 91视频在线看| 国产在线精品免费| 天使萌一区二区三区免费观看| 欧美激情一区在线观看| 日韩视频免费观看高清完整版在线观看| 国产精品 日产精品 欧美精品| 日韩黄色小视频| 亚洲综合男人的天堂| 国产精品青草综合久久久久99| 精品国产a毛片| 日韩一区和二区| 欧美精品日韩综合在线| av电影天堂一区二区在线| 久久国内精品视频| 欧美a一区二区| 亚洲精品日韩一| 亚洲欧洲成人av每日更新| 国产三区在线成人av| 欧美精品一区二区在线观看| 欧美人与性动xxxx| 欧美精品三级在线观看| 欧美三日本三级三级在线播放| 91蝌蚪porny| 一本到一区二区三区| 色老综合老女人久久久| 91麻豆精品视频| 在线观看区一区二| 色网综合在线观看| 欧美色图在线观看| 欧美日韩国产片| 日韩一区二区在线看| 欧美一级淫片007| 精品粉嫩aⅴ一区二区三区四区| 91精品国产91综合久久蜜臀| 日韩亚洲欧美中文三级| 欧美大片顶级少妇| 久久久久久久久一| 国产精品伦一区二区三级视频| 1区2区3区国产精品| 一区二区三区日韩精品| 亚洲成人在线观看视频| 秋霞国产午夜精品免费视频| 麻豆一区二区三| 懂色一区二区三区免费观看| 91麻豆文化传媒在线观看| 欧美专区在线观看一区| 91精品国模一区二区三区| 精品国产乱码久久久久久免费| 亚洲国产精品成人综合色在线婷婷| 中文字幕av免费专区久久| 亚洲精品国产第一综合99久久| 亚洲国产综合色| 国产一区视频在线看| 成人天堂资源www在线| 日本高清不卡一区| 精品国产乱码久久久久久老虎| 国产欧美精品国产国产专区| 亚洲精品自拍动漫在线| 日本在线不卡视频一二三区| 高清国产一区二区| 欧美无砖专区一中文字| 欧美成人女星排名| 亚洲靠逼com| 激情六月婷婷综合| 久久久久国产精品人| 亚洲一区二区综合| 国产一区二区久久| 在线播放亚洲一区| 国产精品久久久99| 秋霞成人午夜伦在线观看| 国产精品99久久久久久宅男| 成人av免费网站| 欧美大片在线观看一区| 亚洲乱码国产乱码精品精98午夜| 青青草国产精品亚洲专区无| 一本一道久久a久久精品| 日韩一区二区三区四区| 亚洲色图欧美偷拍| 精品一区二区三区在线观看| 色综合天天性综合| 久久久不卡网国产精品二区| 一区二区三区日韩精品| 成人午夜视频网站| 日韩久久久久久| 亚洲电影你懂得| 91免费视频网| 国产精品久久毛片a| 久久99久久久欧美国产| 欧美日韩中文字幕一区二区|