Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/avl.c

    ra35b458 r1b20da0  
    6666{
    6767        avltree_node_t *p;
    68 
     68       
    6969        /*
    7070         * Iteratively descend to the leaf that can contain the searched key.
     
    9292{
    9393        avltree_node_t *p = t->root;
    94 
     94       
    9595        /*
    9696         * Check whether the tree is empty.
     
    9898        if (!p)
    9999                return NULL;
    100 
     100       
    101101        /*
    102102         * Iteratively descend to the leftmost leaf in the tree.
     
    104104        while (p->lft != NULL)
    105105                p = p->lft;
    106 
     106       
    107107        return p;
    108108}
     
    151151#define REBALANCE_INSERT_LR()           REBALANCE_INSERT_XY(lft, rgt, 1)
    152152#define REBALANCE_INSERT_RL()           REBALANCE_INSERT_XY(rgt, lft, -1)
    153 
     153       
    154154/** Insert new node into AVL tree.
    155155 *
     
    172172         */
    173173        key = newnode->key + t->base;
    174 
     174       
    175175        /*
    176176         * Iteratively descend to the leaf that can contain the new node.
     
    244244                }
    245245        }
    246 
     246       
    247247        /*
    248248         * To balance the tree, we must check and balance top node.
     
    260260                         */
    261261                        assert(par->balance == 1);
    262 
     262                       
    263263                        REBALANCE_INSERT_LR();
    264264                }
     
    275275                         */
    276276                        assert(par->balance == -1);
    277 
     277               
    278278                        REBALANCE_INSERT_RL();
    279279                }
     
    375375        assert(t);
    376376        assert(node);
    377 
     377       
    378378        if (node->lft == NULL) {
    379379                if (node->rgt) {
     
    451451                cur->par = node->par;
    452452        }
    453 
     453       
    454454        /*
    455455         * Repair the parent node's pointer which pointed previously to the
     
    457457         */
    458458        (void) repair(t, node, node, cur, NULL, false);
    459 
     459       
    460460        /*
    461461         * Repair cycle which repairs balances of nodes on the way from from the
     
    484484                                         * RL rotation.
    485485                                         */
    486 
     486                                       
    487487                                        cur = par->lft;
    488488                                        par->lft = cur->rgt;
     
    490490                                        gpa->rgt = cur->lft;
    491491                                        cur->lft = gpa;
    492 
     492                                       
    493493                                        /*
    494494                                         * Repair balances and paternity of
     
    497497                                         */
    498498                                        REBALANCE_DELETE_RL();
    499 
     499                                       
    500500                                        /*
    501501                                         * Repair paternity.
     
    513513                                         * RR rotation.
    514514                                         */
    515 
     515                                       
    516516                                        gpa->rgt = par->lft;
    517517                                        if (par->lft)
    518518                                                par->lft->par = gpa;
    519519                                        par->lft = gpa;
    520 
     520                                       
    521521                                        /*
    522522                                         * Repair paternity.
     
    524524                                        par->par = gpa->par;
    525525                                        gpa->par = par;
    526 
     526                                       
    527527                                        if (par->balance == 0) {
    528528                                                /*
     
    575575                                 */
    576576                                par = gpa->lft;
    577 
     577                               
    578578                                if (par->balance == 1) {
    579579                                        /*
    580580                                         * LR rotation.
    581581                                         */
    582 
     582                                       
    583583                                        cur = par->rgt;
    584584                                        par->rgt = cur->lft;
     
    586586                                        gpa->lft = cur->rgt;
    587587                                        cur->rgt = gpa;
    588 
     588                                       
    589589                                        /*
    590590                                         * Repair balances and paternity of
     
    619619                                        par->par = gpa->par;
    620620                                        gpa->par = par;
    621 
     621                                       
    622622                                        if (par->balance == 0) {
    623623                                                /*
     
    630630                                                par->balance = 1;
    631631                                                gpa->balance = -1;
    632 
     632                                               
    633633                                                (void) repair(t, par, gpa, par,
    634634                                                    NULL, false);
     
    637637                                                par->balance = 0;
    638638                                                gpa->balance = 0;
    639 
     639                                               
    640640                                                if (!repair(t, par, gpa, par,
    641641                                                    &dir, false))
     
    667667{
    668668        avltree_node_t *node;
    669 
     669       
    670670        /*
    671671         * Start searching for the smallest key in the tree starting in the root
     
    673673         * must have the smallest key).
    674674         */
    675 
     675         
    676676        node = t->root;
    677677        if (!node)
    678678                return false;
    679 
     679       
    680680        while (node->lft != NULL)
    681681                node = node->lft;
    682 
     682       
    683683        avltree_delete(t, node);
    684684
Note: See TracChangeset for help on using the changeset viewer.