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

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

?? btree.cpp

?? 小程序
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/*------------------------------------------------------------------------*/
/*                                                                        */
/*  BTREE.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

/*

Implementation notes:

This implements B-trees with several refinements.  Most of them can be found
in Knuth Vol 3, but some were developed to adapt to restrictions imposed
by C++.  First, a restatement of Knuth's properties that a B-tree must
satisfy, assuming we make the enhancement he suggests in the paragraph
at the bottom of page 476.  Instead of storing null pointers to non-existent
nodes (which Knuth calls the leaves) we utilize the space to store keys.
Therefore, what Knuth calls level (l-1) is the bottom of our tree, and
we call the nodes at this level LeafNodes.  Other nodes are called InnerNodes.
The other enhancement we have adopted is in the paragraph at the bottom of
page 477: overflow control.

The following are modifications of Knuth's properties on page 478:

i)  Every InnerNode has at most Order keys, and at most Order+1 sub-trees.
ii) Every LeafNode has at most 2*(Order+1) keys.
iii)An InnerNode with k keys has k+1 sub-trees.
iv) Every InnerNode that is not the root has at least InnerLowWaterMark keys.
v)  Every LeafNode that is not the root has at least LeafLowWaterMark keys.
vi) If the root is a LeafNode, it has at least one key.
vii)If the root is an InnerNode, it has at least one key and two sub-trees.
viii)All LeafNodes are the same distance from the root as all the other
    LeafNodes.
ix) For InnerNode n with key n[i].key, then sub-tree n[i-1].tree contains
    all keys <= n[i].key, and sub-tree n[i].tree contains all keys >= n[i].key.
x)  Order is at least 3.

The values of InnerLowWaterMark and LeafLowWaterMark may actually be set
by the user when the tree is initialized, but currently they are set
automatically to:
        InnerLowWaterMark = ceiling(Order/2)
        LeafLowWaterMark  = Order - 1

If the tree is only filled, then all the nodes will be at least 2/3 full.
They will almost all be exactly 2/3 full if the elements are added to the
tree in order (either increasing or decreasing).  [Knuth says McCreight's
experiments showed almost 100% memory utilization.  I don't see how that
can be given the algorithms that Knuth gives.  McCreight must have used
a different scheme for balancing.  [ No, he used a different scheme for
splitting: he did a two-way split instead of the three way split as we do
here.  Which means that McCreight does better on insertion of ordered data,
but we should do better on insertion of random data.]]

It must also be noted that B-trees were designed for DISK access algorithms,
not necessarily in-memory sorting, as we intend it to be used here.  However,
if the order is kept small (< 6?) any inefficiency is negligible for
in-memory sorting.  Knuth points out that balanced trees are actually
preferable for memory sorting.  I'm not sure that I believe this, but
it's interesting.  Also, deleting elements from balanced binary trees, being
beyond the scope of Knuth's book (p. 465), is beyond my scope.  B-trees
are good enough.


A B-tree is declared to be of a certain ORDER (4 by default).  This number
determines the number of keys contained in any interior node of the tree.
Each interior node will contain ORDER keys, and therefore ORDER+1 pointers
to sub-trees.  The keys are numbered and indexed 1 to ORDER while the
pointers are numbered and indexed 0 to ORDER.  The 0th ptr points to the
sub-tree of all elements that are less than key[1].  Ptr[1] points to the
sub-tree that contains all the elements greater than key[1] and less than
key[2].  etc.  The array of pointers and keys is allocated as ORDER+1
pairs of keys and nodes, meaning that one key field (key[0]) is not used
and therefore wasted.  Given that the number of interior nodes is
small, that this waste allows fewer cases of special code, and that it
is useful in certain of the methods, it was felt to be a worthwhile waste.

The size of the exterior nodes (leaf nodes) does not need to be related to
the size of the interior nodes at all.  Since leaf nodes contain only
keys, they may be as large or small as we like independent of the size
of the interior nodes.  For no particular reason other than it seems like
a good idea, we will allocate 2*(ORDER+1) keys in each leaf node, and they
will be numbered and indexed from 0 to 2*ORDER+1.  It does have the advantage
of keeping the size of the leaf and interior arrays the same, so that if we
find allocation and de-allocation of these arrays expensive, we can modify
their allocation to use a garbage ring, or something.

Both of these numbers will be run-time constants associated with each tree
(each tree at run-time can be of a different order).  The variable `order'
is the order of the tree, and the inclusive upper limit on the indices of
the keys in the interior nodes.  The variable `order2' is the inclusive
upper limit on the indices of the leaf nodes, and is designed
    (1) to keep the sizes of the two kinds of nodes the same;
    (2) to keep the expressions involving the arrays of keys looking
        somewhat the same:   lower limit        upper limit
          for inner nodes:        1                order
          for leaf  nodes:        0                order2
        Remember that index 0 of the inner nodes is special.

Currently, order2 = 2*(order+1).

 picture: (also see Knuth Vol 3 pg 478)

           +--+--+--+--+--+--...
           |  |  |  |  |  |
 parent--->|  |     |     |
           |  |     |     |
           +*-+*-+*-+--+--+--...
            |  |  |
       +----+  |  +-----+
       |       +-----+  |
       V             |  V
       +----------+  |  +----------+
       |          |  |  |          |
 this->|          |  |  |          |<--sib
       +----------+  |  +----------+
                     V
                    data

It is conceptually VERY convenient to think of the data as being the
very first element of the sib node.  Any primitive that tells sib to
perform some action on n nodes should include this `hidden' element.
For InnerNodes, the hidden element has (physical) index 0 in the array,
and in LeafNodes, the hidden element has (virtual) index -1 in the array.
Therefore, there are two `size' primitives for nodes:
Psize       - the physical size: how many elements are contained in the
              array in the node.
Vsize       - the `virtual' size; if the node is pointed to by
              element 0 of the parent node, then Vsize == Psize;
              otherwise the element in the parent item that points to this
              node `belongs' to this node, and Vsize == Psize+1;

Parent nodes are always InnerNodes.

These are the primitive operations on Nodes:

append(elt)     - adds an element to the end of the array of elements in a
                  node.  It must never be called where appending the element
                  would fill the node.
split()         - divide a node in two, and create two new nodes.
splitWith(sib)  - create a third node between this node and the sib node,
                  divvying up the elements of their arrays.
pushLeft(n)     - move n elements into the left sibling
pushRight(n)    - move n elements into the right sibling
balanceWithRight() - even up the number of elements in the two nodes.
balanceWithLeft()  - ditto


To allow this implementation of btrees to also be an implementation of
sorted arrays/lists, the overhead is included to allow O(log n) access
of elements by their rank (`give me the 5th largest element').
Therefore, each Item keeps track of the number of keys in and below it
in the tree (remember, each item's tree is all keys to the RIGHT of the
item's own key).

[ [ < 0 1 2 3 > 4 < 5 6 7 > 8 < 9 10 11 12 > ] 13 [ < 14 15 16 > 17 < 18 19 20 > ] ]
   4  1 1 1 1   4   1 1 1   5   1  1  1  1      7  3   1  1  1    4    1  1  1
*/

//====== Btree functions ========

void Btree::finishInit( int O )
{
    if( O < 3 )
        ClassLib_error( __EORDER3 );
    ownsElements( 0 );
    root = 0;
    Order = O;
    Order2 = 2 * (O+1);
    Leaf_MaxIndex = Order2 - 1;     // item[0..Order2-1]
    Inner_MaxIndex = Order;         // item[1..Order]
    //
    // the low water marks trigger an exploration for balancing
    // or merging nodes.
    // When the size of a node falls below X, then it must be possible to
    // either balance this node with another node, or it must be possible
    // to merge this node with another node.
    // This can be guaranteed only if (this->size() < (maxSize()-1)/2).
    //
    //
    Leaf_LowWaterMark = ((Leaf_MaxIndex+1            // == maxSize()
                                         )-1) / 2    // satisfies the above
                                                  - 1; // because we compare
                                                     // lowwatermark with last

    Inner_LowWaterMark = (Order-1) / 2;
}

Btree::Btree(int O) : itemsInContainer(0)
{
    finishInit(O);
}

Btree::~Btree(void)
{
    if( root != 0 )
        delete root;
}

void Btree::flush( DeleteType dt )
{
    int oldValue = ownsElements();
    ownsElements( delObj(dt) );
    if( root != 0 )
        delete root;
    itemsInContainer = 0;
    root = 0;
    ownsElements( oldValue );
}

int Btree::hasMember( Object& o ) const
{
    if( !o.isSortable() )
        ClassLib_error( __ENOTSORT );
    if( root == 0 )
        return 0;
    else
        {
        Node* loc;
        int idx;
        return root->found(&(Sortable&)o, &loc, &idx) != NOOBJECT;
        }
}

long Btree::rank( const Object& o ) const
{
    if( !o.isSortable() )
        ClassLib_error( __ENOTSORT );
    if( root == 0 )
        return -1;
    else
        return root->findRank(&(Sortable&)o);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产91精品精华液一区二区三区| 亚洲国产欧美另类丝袜| 蜜臀av性久久久久蜜臀aⅴ四虎| 成人av资源在线观看| 欧美成人在线直播| 亚洲一区免费观看| 99免费精品在线| 久久综合九色综合97婷婷女人| 在线视频欧美精品| 色综合久久中文字幕| 久久精品一区八戒影视| 天堂在线一区二区| 色婷婷精品大在线视频| 国产精品国产三级国产a | 国产精品高清亚洲| 国产一区二区三区四区在线观看| 91.com视频| 香蕉加勒比综合久久| 91无套直看片红桃| 国产精品日产欧美久久久久| 九色综合狠狠综合久久| 日韩一区二区三区免费观看| 午夜久久电影网| 欧美视频精品在线观看| 亚洲乱码国产乱码精品精小说 | 成人激情免费视频| 久久久91精品国产一区二区三区| 六月婷婷色综合| 欧美熟乱第一页| 一区二区成人在线观看| 99久久精品国产导航| 国产精品美日韩| 成人中文字幕在线| 亚洲精品国产a久久久久久| 综合av第一页| 成人91在线观看| 欧美激情在线一区二区三区| 精品一区二区在线视频| 欧美sm美女调教| 精品一区二区三区在线观看 | 国产在线国偷精品免费看| 日韩欧美国产综合在线一区二区三区| 日韩**一区毛片| 日韩免费视频一区二区| 久久精品免费看| 精品国产乱子伦一区| 国产一区二区按摩在线观看| 欧美精品一区二区蜜臀亚洲| 国产美女av一区二区三区| 国产免费成人在线视频| 99精品视频在线播放观看| 亚洲三级小视频| 欧美在线你懂得| 日韩专区中文字幕一区二区| 5858s免费视频成人| 日本不卡一区二区| 精品福利二区三区| 成人中文字幕在线| 亚洲免费观看高清完整版在线观看 | 亚洲一区精品在线| **欧美大码日韩| 免费成人在线网站| 精品国产成人系列| 成人一级视频在线观看| 中文字幕亚洲一区二区av在线 | 国产福利91精品| 亚洲欧美综合在线精品| 欧美自拍偷拍午夜视频| 日韩av电影免费观看高清完整版 | 欧美酷刑日本凌虐凌虐| 经典三级视频一区| 国产精品久久久久一区 | 成人手机电影网| 亚洲欧美一区二区三区国产精品| 欧美日本在线看| 久久99热狠狠色一区二区| 欧美激情一区二区三区全黄 | 久久99九九99精品| 国产精品欧美一区二区三区| 欧美亚洲图片小说| 久久精品国产久精国产| 亚洲欧洲精品一区二区精品久久久 | 欧美日韩大陆一区二区| 国模冰冰炮一区二区| 亚洲视频一区二区在线观看| 欧美精品一级二级三级| 国产福利一区二区三区视频在线| 亚洲激情图片小说视频| 欧美不卡一区二区| 色婷婷久久综合| 久久精品久久精品| 亚洲欧美视频在线观看视频| 欧美一卡2卡三卡4卡5免费| 成人免费视频国产在线观看| 五月激情综合网| 中文一区二区在线观看| 91精品国产综合久久婷婷香蕉| 风间由美一区二区av101| 亚洲成人免费影院| 国产精品三级av在线播放| 欧美男男青年gay1069videost | 成人精品视频一区| 亚洲成人午夜影院| 国产精品电影院| 精品久久久久久久久久久久包黑料 | 国产老妇另类xxxxx| 一个色妞综合视频在线观看| 久久久久国产成人精品亚洲午夜| 欧美三片在线视频观看| 成人精品国产免费网站| 久久精品99国产精品| 久久精品国产一区二区三区免费看 | 成人av资源站| 寂寞少妇一区二区三区| 亚洲va韩国va欧美va| 国产精品免费久久| 久久中文娱乐网| 91超碰这里只有精品国产| 一本一道久久a久久精品综合蜜臀| 精品一区二区免费| 天堂一区二区在线免费观看| 亚洲视频一二区| 国产精品私房写真福利视频| 亚洲精品一区二区三区蜜桃下载| 精品视频色一区| 色综合视频一区二区三区高清| 国产91丝袜在线播放| 久久99久久精品| 免费在线观看精品| 午夜电影网亚洲视频| 亚洲卡通动漫在线| 国产精品久久久一本精品 | 欧美撒尿777hd撒尿| 不卡的av网站| 丁香天五香天堂综合| 黑人巨大精品欧美黑白配亚洲| 手机精品视频在线观看| 亚洲永久免费av| 亚洲精品国产视频| 亚洲欧美综合网| 18欧美亚洲精品| 国产精品免费视频一区| 国产精品美女久久久久久 | 亚洲国产精品久久一线不卡| 国产亚洲精品aa| 精品三级在线观看| 欧美va在线播放| 欧美va亚洲va国产综合| 精品美女被调教视频大全网站| 91精品国产91久久综合桃花| 欧美美女网站色| 91麻豆精品国产91久久久使用方法 | www.av亚洲| 99久久综合99久久综合网站| 99综合影院在线| 99精品视频在线播放观看| 91麻豆精品一区二区三区| 91日韩精品一区| 色8久久人人97超碰香蕉987| 在线观看网站黄不卡| 欧美在线观看一二区| 欧美日韩一二区| 91精品国产全国免费观看| 欧美一区二区在线观看| 日韩一区二区免费在线观看| 日韩欧美在线影院| 2020国产精品久久精品美国| 国产女人水真多18毛片18精品视频 | 2024国产精品| 中文天堂在线一区| 亚洲精品午夜久久久| 亚洲国产美国国产综合一区二区| 午夜精品免费在线| 美女视频一区二区| 国产精品69毛片高清亚洲| 国产精品一区一区| 成人一区二区三区中文字幕| 91麻豆123| 欧美日韩三级一区| 日韩午夜在线观看| 国产欧美精品国产国产专区| 国产精品国产自产拍在线| 亚洲一区在线观看免费观看电影高清| 日韩成人免费看| 国产在线不卡一区| 色综合久久久久综合体桃花网| 欧美日韩免费电影| 日韩女同互慰一区二区| 国产嫩草影院久久久久| 亚洲一区二区在线免费看| 日韩电影一区二区三区| 国产99久久久国产精品潘金| 91麻豆精品秘密| 欧美一区二区三区成人| 国产女人aaa级久久久级 | 亚洲图片欧美色图| 久久福利资源站| 91影视在线播放| 日韩一区二区不卡| 国产亚洲精品bt天堂精选|