Changeset 1226


Ignore:
Timestamp:
Aug 15, 2003, 10:11:57 AM (17 years ago)
Author:
pooh
Message:
  • Table::insert_node() fixes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/runtime/rf_table.cc

    r1221 r1226  
    1111size_t Table::count = 0;
    1212
    13 // 
    14 // inserting of element newNode in this-Table 
     13//
     14// inserting of element newNode in this-Table
    1515void Table::insert_node (TableNode* _node)
    16 { 
     16{
    1717  TableNode* x;
    1818  TableNode* y;
    1919  int flag;
    2020  y = TableNode::nil;
    21   x = root;   
     21  x = root;
    2222  while (x != TableNode::nil) {
    2323    y=x;
    24     if ((_node->hash_key) == (x->hash_key)) { 
     24    if ((_node->hash_key) == (x->hash_key)) {
    2525      flag = Expr::compare(_node->key, x->key);
    26       if (!flag)                    //   case 0 :  ==
     26      if (!flag) {                      //   case 0 :  ==
    2727        return;
    28       if (flag < 0) {               //   case < 0 : <
     28      } else if (flag < 0) {            //   case < 0 : <
    2929        x = x->left;
    30         continue;
    3130      } else {
    3231        x = x->right;
    33         continue;
    34       }
     32      }
     33    } else if ((_node->hash_key) < (x->hash_key)) {
     34      x = x->left;
     35    } else {
     36      x = x->right;
    3537    }
    36     if ((_node->hash_key) < (x->hash_key))
    37       x = x->left;
    38     else
    39       x = x->right;
    4038  }
    4139  _node->p = y;
    42   if (y == TableNode::nil)
    43     root = _node; 
    44   else
    45     if ((_node->hash_key) == (x->hash_key)) { 
    46       flag = Expr::compare(_node->key, x->key);
     40  if (y == TableNode::nil) {
     41    root = _node;
     42  } else {
     43    //
     44    // FIXME: Here we already chosen valid direction, so probably we
     45    // should introduce a flag indicating that direction to avoid possible
     46    // duplicated compare(). [pooh 2003-08-15]
     47    if ((_node->hash_key) == (y->hash_key)) {
     48      flag = Expr::compare(_node->key, y->key);
    4749      if (flag < 0) {
    4850        y->left = _node;
    49         return;
    5051      } else {
    5152        y->right = _node;
    52         return;
    53       }
    54     }   
    55   if ((_node->hash_key) < (y->hash_key))
    56     y->left = _node;
    57   else
    58     y->right = _node;
     53      }
     54    } else if ((_node->hash_key) < (y->hash_key)) {
     55      y->left = _node;
     56    } else {
     57      y->right = _node;
     58    }
     59  }
    5960}
    6061
Note: See TracChangeset for help on using the changeset viewer.