当前位置: 首页>>代码示例>>C++>>正文


C++ BNode::GetKeyOfNode方法代码示例

本文整理汇总了C++中BNode::GetKeyOfNode方法的典型用法代码示例。如果您正苦于以下问题:C++ BNode::GetKeyOfNode方法的具体用法?C++ BNode::GetKeyOfNode怎么用?C++ BNode::GetKeyOfNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BNode的用法示例。


在下文中一共展示了BNode::GetKeyOfNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BulkLoad

// -------------------------------------------------------------------------
// Bulkload b-tree from hash table in mem
// <pairs>: 
// <num>: number of entries
void BTree::BulkLoad(Pair* pairs, int num) {

    int start_block = -1;
    int end_block   = -1;

    BNode* prev_node = NULL;
    BNode* cur_node  = NULL;

    bool first_node = true;

    // ---------------------------------------------------------------------
    //  Build leaf node from <pairs> (level = 0)
    // ---------------------------------------------------------------------
    for (int i = 0; i < num; ++i) {

        int id = pairs[i].id();
        float key = pairs[i].projection();

        if (cur_node == NULL) {
            cur_node = new BNode();
            cur_node->Init(0, this);

            if (first_node) {
                first_node = false;
                start_block = cur_node->block();
            } else {
                cur_node->set_left_sibling(prev_node);
                prev_node->set_right_sibling(cur_node);

                delete prev_node;
                prev_node = NULL;
            }
            end_block = cur_node->block();
        }
        cur_node->AddNewChild(key, id);

        if (cur_node->IsFull()) {
            prev_node = cur_node;
            cur_node = NULL;
        }
    }

    // release space
    delete prev_node;
    prev_node = NULL;

    delete cur_node;
    cur_node = NULL;

    // -------------------------------------------------------------------------
    //  Build the b-tree level by level
    // -------------------------------------------------------------------------
    int cur_level = 1;
    int last_start_block = start_block;
    int last_end_block   = end_block;

    // when lastEndBlock == lastStartBlock mean it's only one node, as root
    while (last_end_block > last_start_block) {
        first_node = true;
        for (int block = last_start_block; block <= last_end_block; ++block) {

            BNode* child = new BNode();
            child->InitFromFile(this, block);

            float key = child->GetKeyOfNode();

            delete child;

            if (cur_node == NULL) {
                cur_node = new BNode();
                cur_node->Init(cur_level, this);

                if (first_node) {
                    first_node = false;
                    start_block = cur_node->block();
                } else {
                    cur_node->set_left_sibling(prev_node);
                    prev_node->set_right_sibling(cur_node);

                    delete prev_node;
                    prev_node = NULL;
                }
                end_block = cur_node->block();
            }
            cur_node->AddNewChild(key, block);

            if (cur_node->IsFull()) {
                prev_node = cur_node;
                cur_node = NULL;
            }
        }

        // next level
        cur_level++;
        last_start_block = start_block;
        last_end_block   = end_block;
//.........这里部分代码省略.........
开发者ID:xughv,项目名称:DBProject,代码行数:101,代码来源:b_tree.cpp


注:本文中的BNode::GetKeyOfNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。