Changeset 1221


Ignore:
Timestamp:
Aug 14, 2003, 11:42:48 PM (17 years ago)
Author:
orlov
Message:
  • Expr::compare() can return any integer. Sign is what matters.
Location:
to-imperative/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/Compare/compare.cc

    r960 r1221  
    1616
    1717RF_FUNC (Compare, (RF_ARG e_Exp1, e_Exp2), (RF_RES s_Res))
    18   static const Expr res[] = {
    19     Char::create_expr("<"),
    20     Char::create_expr("="),
    21     Char::create_expr(">")
    22   };
    23   s_Res = res[Expr::compare(e_Exp1, e_Exp2) + 1];
     18  static const Expr lt = Char::create_expr("<");
     19  static const Expr eq = Char::create_expr("=");
     20  static const Expr gt = Char::create_expr(">");
     21
     22  int res = Expr::compare(e_Exp1, e_Exp2);
     23 
     24  s_Res = res > 0 ? gt : (res ? lt : eq);
    2425RF_END
    2526
  • to-imperative/trunk/library/Compare/gt.cc

    r928 r1221  
    1717RF_FUNC (_gt_, (RF_ARG e_Exp1, e_Exp2), ())
    1818
    19   if (Expr::compare(e_Exp1, e_Exp2) != 1)
     19  if (Expr::compare(e_Exp1, e_Exp2) <= 0)
    2020    retfail;
    2121
  • to-imperative/trunk/library/Compare/gt_eq.cc

    r947 r1221  
    1717RF_FUNC (_gt__eq_, (RF_ARG e_Exp1, e_Exp2), ())
    1818
    19   if (Expr::compare(e_Exp1, e_Exp2) == -1)
     19  if (Expr::compare(e_Exp1, e_Exp2) < 0)
    2020    retfail;
    2121
  • to-imperative/trunk/library/Compare/lt.cc

    r928 r1221  
    1717RF_FUNC (_lt_, (RF_ARG e_Exp1, e_Exp2), ())
    1818
    19   if (Expr::compare(e_Exp1, e_Exp2) != -1)
     19  if (Expr::compare(e_Exp1, e_Exp2) >= 0)
    2020    retfail;
    2121
  • to-imperative/trunk/library/Compare/lt_eq.cc

    r947 r1221  
    1717RF_FUNC (_lt__eq_, (RF_ARG e_Exp1, e_Exp2), ())
    1818
    19   if (Expr::compare(e_Exp1, e_Exp2) == 1)
     19  if (Expr::compare(e_Exp1, e_Exp2) > 0)
    2020    retfail;
    2121
  • to-imperative/trunk/runtime/rf_expr.hh

    r1140 r1221  
    182182  inline bool operator != (Expr const& _expr) const ;
    183183  ///
    184   /// Compare two expressions.  Return 1 if first expression is larger then
    185   /// second one, 0 if they are equal, and -1 if first one is smaller then
    186   /// second one.
     184  /// Compare two expressions.  Return integer > 0 if first expression is
     185  /// larger then second one, 0 if they are equal, and integer < 0 if first one
     186  /// is smaller then second one.
    187187  static inline int compare (Expr const& _expr1, Expr const& _expr2) ;
    188188  ///
  • to-imperative/trunk/runtime/rf_table.cc

    r1124 r1221  
    2626      if (!flag)                    //   case 0 :  ==
    2727        return;
    28       if (flag == -1){              //   case -1 : <
     28      if (flag < 0) {               //   case < 0 : <
    2929        x = x->left;
    3030        continue;
     
    4545    if ((_node->hash_key) == (x->hash_key)) { 
    4646      flag = Expr::compare(_node->key, x->key);
    47       if (flag == -1) {          //  case -1 : <
     47      if (flag < 0) {
    4848        y->left = _node;
    4949        return;
     
    238238  hash = expr_hash(_key);
    239239  node = root; 
    240   while ((node != TableNode::nil) && (node->hash_key != hash))
     240  while ((node != TableNode::nil) && (node->hash_key != hash)) {
    241241    if (hash < node->hash_key)
    242242      node = node->left;
    243243    else
    244       node = node->right;   
     244      node = node->right;
     245  }
    245246  while ((node != TableNode::nil) && (hash == node->hash_key)) {
    246247    flag = Expr::compare(_key, node->key);
    247248    if (!flag)            //   case 0 : ==
    248249      return (node);
    249     if (flag == -1)       //   case -1 : <
     250    if (flag < 0)         //   case < 0 : <
    250251      node = node->left;
    251252    else
Note: See TracChangeset for help on using the changeset viewer.