Changeset 4018


Ignore:
Timestamp:
Oct 31, 2008, 7:08:08 PM (12 years ago)
Author:
yura
Message:
  • QSortBy, QSortAndNumBy.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/refal/refal/plus/List2.rf

    r4012 r4018  
    245245//  e.list;
    246246
    247 $func QSort_Split t.num e.list = (e.list) (e.list);
    248 QSort_Split t.num e.list,
    249   () () e.list $iter {
    250     e.list : t.head e.tail, {
    251       <Le (t.head) (t.num)> = (e.smaller t.head) (e.greater) e.tail;
    252       = (e.smaller) (e.greater t.head) e.tail;
    253     };
    254   } :: (e.smaller) (e.greater) e.list, e.list : /*empty*/ =
    255   (e.smaller) (e.greater);
    256 
    257 $public $func QSort e.list = e.list;
    258 QSort {
    259   /* empty */   = /* empty */;
    260   t.head e.tail = <QSort_Split t.head e.tail> :: (e.smaller) (e.greater),
    261     <QSort e.smaller> t.head <QSort e.greater>;
    262 };
    263 
    264247$public $func CompareTerms t.term t.term = s.cmp;
    265248CompareTerms t.term1 t.term2 = <Compare (t.term1) (t.term2)>;
     249
     250$func QSort_Split t.cmpTerm e.list = (e.smaller) (e.equal) (e.greater);
     251QSort_Split t.cmpTerm e.list,
     252  () () () e.list $iter {
     253    e.list : t.head e.tail,
     254      <Apply t.cmpTerm t.head> : {
     255        '<' = (e.smaller) (e.equal) (e.greater t.head) e.tail;
     256        '=' = (e.smaller) (e.equal t.head) (e.greater) e.tail;
     257        '>' = (e.smaller t.head) (e.equal) (e.greater) e.tail;
     258    };
     259  } :: (e.smaller) (e.equal) (e.greater) e.list, e.list : /*empty*/ =
     260  (e.smaller) (e.equal) (e.greater);
     261
     262$public $func QSortBy t.cmpTerms e.list = e.list;
     263QSortBy t.cmpTerms e.list = e.list : {
     264  /* empty */   = /* empty */;
     265  t.head e.tail = <QSort_Split (t.cmpTerms t.head) e.tail> :: (e.smaller) (e.equal) (e.greater),
     266    <QSort e.smaller> t.head e.equal <QSort e.greater>;
     267};
     268
     269$public $func QSort e.list = e.list;
     270QSort e.list = <QSortBy &CompareTerms e.list>;
     271
     272$public $func QSortAndNubBy t.cmpTerms e.list = e.list;
     273QSortAndNubBy t.cmpTerms e.list = e.list : {
     274  /* empty */   = /* empty */;
     275  t.head e.tail = <QSort_Split (t.cmpTerms t.head) e.tail> :: (e.smaller) t (e.greater),
     276    <QSort e.smaller> t.head <QSort e.greater>;
     277};
     278
     279$public $func QSortAndNub e.list = e.list;
     280QSortAndNub e.list = <QSortAndNubBy &CompareTerms e.list>;
    266281
    267282$public $func Sort e.list = e.list;
Note: See TracChangeset for help on using the changeset viewer.