代码

来源:互联网 发布:c 高级编程第6版 pdf 编辑:程序博客网 时间:2024/05/30 23:08

2

int insert_btree(BtreeRoot& btree_root, const T& tobj) {    // step1 查找元素该插入的位置,并记录路径btree_path用于回溯    // step2 insert btree bottom-up: 自底向上    T cur_key;    uint64_t cur_rchild;    while (btree_path.not_empty()){        // CASE1 directly: 如果结点还有空闲位置则直接插入        if (p_cur_node->key_num() < MAX_KEY_NUM) {            return insert_directly(...);        }         // 先将key插入进去后面再rebalance或者adjust        ExtraKey extra_pair;  // 逻辑连续        p_cur_node->_insert_full_node(...);                // case2 rebalance: 如果左右兄弟还有空位直接移动        if (check_bros_not_full) {            return insert_by_rebalance(...);           } else {        // case3 adjust: 左右兄弟都满了需要创建一个结点调整            ret = insert_by_adjust(...);                       // 向上回溯一层            btree_path.pop();            cur_key = new_key;            cur_rchild = new_rchild;        }<span style="white-space:pre"></span>}    <span style="white-space:pre"></span>return 0;}


原创粉丝点击