Changeset 873
- Timestamp:
- Jun 26, 2003, 1:16:21 PM (18 years ago)
- Location:
- to-imperative/trunk/runtime
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
to-imperative/trunk/runtime/rf_expr.hh
r860 r873 186 186 inline bool operator == (Expr const& _expr) const ; 187 187 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) ; 188 193 /// 189 194 /// Get pointer to a memory block containing an expression -
to-imperative/trunk/runtime/rf_expr.ih
r862 r873 437 437 { 438 438 return !(self == _expr); 439 } 440 441 inline 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()); 439 445 } 440 446 -
to-imperative/trunk/runtime/rf_term.cc
r860 r873 75 75 } 76 76 77 int 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 77 83 // 78 84 // FIXME: implement this … … 86 92 (void (*)(Term*))(Term::ref_dtor), 87 93 (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), 89 95 null, // (uint32_t (*)(Term const*))(ref_hash), FIXME: 90 96 (pxx::WString (*)(Term const*))(Term::ref_to_string) -
to-imperative/trunk/runtime/rf_term.hh
r862 r873 139 139 static void ref_dtor (Term* _term) ; 140 140 static bool ref_eq (Term const* _term1, Term const* _term2) ; 141 static int ref_compare (Term const* _term1, Term const* _term2) ; 141 142 static pxx::WString ref_to_string (Term const* _term) ; 142 143 static short_type_funcs_t ref_funcs ; … … 206 207 207 208 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 ) ; 208 214 209 215 #if defined(RF_STORE_CHUNK_ORDER_IN_TERM) -
to-imperative/trunk/runtime/rf_term.ih
r862 r873 132 132 inline bool Term::operator == (Term const& _t) const 133 133 { 134 if (is_ref() && _t.is_ref()) return ref_eq(this, &_t); 134 135 if (data1 != _t.data1) return false; 135 136 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; 137 138 if (pf && (*pf)(this, &_t)) return true; 138 139 return false; … … 210 211 inline Term::operator pxx::WString () const 211 212 { 212 return (*(short_type_funcs[get_type()]->to_string))(this); 213 return (*(short_type_funcs[get_short_type()]->to_string))(this); 214 } 215 216 inline 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 231 inline 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; 213 254 } 214 255
Note: See TracChangeset
for help on using the changeset viewer.