Changeset 873


Ignore:
Timestamp:
Jun 26, 2003, 1:16:21 PM (18 years ago)
Author:
orlov
Message:
  • Method Expr::compare.
Location:
to-imperative/trunk/runtime
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/runtime/rf_expr.hh

    r860 r873  
    186186  inline bool operator == (Expr const& _expr) const ;
    187187  inline bool operator != (Expr const& _expr) const ;
     188  ///
     189  /// Compare two expressions.  Return 1 if first expression is larger then
     190  /// second one, 0 if they are equal, and -1 if first one is smaller then
     191  /// second one.
     192  static inline int compare (Expr const& _expr1, Expr const& _expr2) ;
    188193  ///
    189194  /// Get pointer to a memory block containing an expression
  • to-imperative/trunk/runtime/rf_expr.ih

    r862 r873  
    437437{
    438438  return !(self == _expr);
     439}
     440
     441inline int Expr::compare (Expr const& _expr1, Expr const& _expr2)
     442{
     443  return Term::compare(_expr1.get_first(), _expr1.get_last(),
     444                       _expr2.get_first(), _expr2.get_last());
    439445}
    440446
  • to-imperative/trunk/runtime/rf_term.cc

    r860 r873  
    7575}
    7676
     77int Term::ref_compare (Term const* _term1, Term const* _term2)
     78{
     79  return compare(_term1->get_first(), _term1->get_last(),
     80                 _term2->get_first(), _term2->get_last());
     81}
     82
    7783//
    7884// FIXME: implement this
     
    8692  (void (*)(Term*))(Term::ref_dtor),
    8793  (bool (*)(Term const*, Term const*))(Term::ref_eq),
    88   null, // (int (*)(Term const*, Term const*))(ref_compare), FIXME:
     94  (int  (*)(Term const*, Term const*))(Term::ref_compare),
    8995  null, // (uint32_t (*)(Term const*))(ref_hash), FIXME:
    9096  (pxx::WString (*)(Term const*))(Term::ref_to_string)
  • to-imperative/trunk/runtime/rf_term.hh

    r862 r873  
    139139  static void ref_dtor (Term* _term) ;
    140140  static bool ref_eq (Term const* _term1, Term const* _term2) ;
     141  static int ref_compare (Term const* _term1, Term const* _term2) ;
    141142  static pxx::WString ref_to_string (Term const* _term) ;
    142143  static short_type_funcs_t ref_funcs ;
     
    206207
    207208  inline operator pxx::WString () const ;
     209
     210  static inline int compare (Term const& _t1, Term const& _t2) ;
     211  static inline int compare (
     212    Term const* _f1, Term const* _l1, Term const* _f2, Term const* _l2
     213  ) ;
    208214
    209215#if defined(RF_STORE_CHUNK_ORDER_IN_TERM)
  • to-imperative/trunk/runtime/rf_term.ih

    r862 r873  
    132132inline bool Term::operator == (Term const& _t) const
    133133{
     134  if (is_ref() && _t.is_ref()) return ref_eq(this, &_t);
    134135  if (data1 != _t.data1) return false;
    135136  if (uint_data2 == _t.uint_data2) return true;
    136   bool (*pf)(Term const*, Term const*) = short_type_funcs[get_type()]->eq;
     137  bool (*pf)(Term const*, Term const*) = short_type_funcs[get_short_type()]->eq;
    137138  if (pf && (*pf)(this, &_t)) return true;
    138139  return false;
     
    210211inline Term::operator pxx::WString () const
    211212{
    212   return (*(short_type_funcs[get_type()]->to_string))(this);
     213  return (*(short_type_funcs[get_short_type()]->to_string))(this);
     214}
     215
     216inline int Term::compare (Term const& _t1, Term const& _t2)
     217{
     218  unsigned type1 = _t1.get_short_type();
     219  unsigned type2 = _t2.get_short_type();
     220  if (type1 == type_ref && type2 != type_ref) return 1;
     221  if (type1 != type_ref && type2 == type_ref) return -1;
     222  if (type1 > type2) return 1;
     223  if (type1 < type2) return -1;
     224  int (*cmp)(Term const*, Term const*) = short_type_funcs[type1]->compare;
     225  if (cmp) return (*cmp)(&_t1, &_t2);
     226  if (_t1.uint_data2 > _t2.uint_data2) return 1;
     227  if (_t1.uint_data2 < _t2.uint_data2) return -1;
     228  return 0;
     229}
     230
     231inline int Term::compare (
     232  Term const* _f1, Term const* _l1, Term const* _f2, Term const* _l2
     233)
     234{
     235  uintptr_t len1 = _l1 - _f1;
     236  uintptr_t len2 = _l2 - _f2;
     237  int compare_len = -1;
     238  uintptr_t min_len = len1;
     239  if (len1 > len2)
     240  {
     241    compare_len = 1;
     242    min_len = len2;
     243  }
     244  else if (len1 == len2)
     245  {
     246    compare_len = 0;
     247  }
     248  for (; min_len; min_len--)
     249  {
     250    int res = Term::compare(*_f1++, *_f2++);
     251    if (res) return res;
     252  }
     253  return compare_len;
    213254}
    214255
Note: See TracChangeset for help on using the changeset viewer.