Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3358

Show
Ignore:
Timestamp:
03/15/08 14:49:29 (9 months ago)
Author:
kris
Message:

changed Sorting mechanism to use a delegate instead of an interface

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/util/collection/ArraySeq.d

    r2809 r3358  
    618618                int mid = (lo + hi) / 2; 
    619619 
    620                 if (cmp.compare(s[lo], s[mid]) > 0) 
     620                if (cmp(s[lo], s[mid]) > 0) 
    621621                   { 
    622622                   T tmp = s[lo]; 
     
    625625                   } 
    626626 
    627                 if (cmp.compare(s[mid], s[hi]) > 0) 
     627                if (cmp(s[mid], s[hi]) > 0) 
    628628                   { 
    629629                   T tmp = s[mid]; 
     
    631631                   s[hi] = tmp; // swap 
    632632 
    633                    if (cmp.compare(s[lo], s[mid]) > 0) 
     633                   if (cmp(s[lo], s[mid]) > 0) 
    634634                      { 
    635635                      T tmp2 = s[lo]; 
     
    648648                for (;;) 
    649649                    { 
    650                     while (cmp.compare(s[right], partition) > 0) 
     650                    while (cmp(s[right], partition) > 0) 
    651651                           --right; 
    652652 
    653                     while (left < right && cmp.compare(s[left], partition) <= 0) 
     653                    while (left < right && cmp(s[left], partition) <= 0) 
    654654                           ++left; 
    655655 
  • trunk/tango/util/collection/TreeBag.d

    r2809 r3358  
    2323private import  tango.util.collection.impl.RBCell, 
    2424                tango.util.collection.impl.BagCollection, 
    25                 tango.util.collection.impl.AbstractIterator, 
    26                 tango.util.collection.impl.DefaultComparator; 
     25                tango.util.collection.impl.AbstractIterator; 
    2726 
    2827/** 
     
    102101                    cmp_ = cmp; 
    103102                else 
    104                    cmp_ = new DefaultComparator!(T); 
    105         } 
     103                   cmp_ = &compare; 
     104        } 
     105 
     106        /** 
     107         * The default comparator 
     108         * 
     109         * @param fst first argument 
     110         * @param snd second argument 
     111         * Returns: a negative number if fst is less than snd; a 
     112         * positive number if fst is greater than snd; else 0 
     113        **/ 
     114 
     115        private final int compare(T fst, T snd) 
     116        { 
     117                if (fst is snd) 
     118                    return 0; 
     119 
     120                return typeid(T).compare (&fst, &snd); 
     121        } 
     122 
    106123 
    107124        /** 
     
    193210                       cmp_ = cmp; 
    194211                   else 
    195                       cmp_ = new DefaultComparator!(T)
     212                      cmp_ = &compare
    196213 
    197214                   if (count !is 0) 
     
    328345                   for (;;) 
    329346                       { 
    330                        int diff = cmp_.compare(element, t.element()); 
     347                       int diff = cmp_(element, t.element()); 
    331348                       if (diff is 0 && checkOccurrence) 
    332349                           return ; 
     
    417434                         T v = t.element(); 
    418435                         if (last !is T.init) 
    419                              assert(cmp_.compare(last, v) <= 0); 
     436                             assert(cmp_(last, v) <= 0); 
    420437                         last = v; 
    421438                         t = t.successor(); 
  • trunk/tango/util/collection/TreeMap.d

    r2809 r3358  
    509509                   for (;;) 
    510510                       { 
    511                        int diff = cmp.compare(key, t.key()); 
     511                       int diff = cmp(key, t.key()); 
    512512                       if (diff is 0 && checkOccurrence) 
    513513                          { 
     
    568568                         { 
    569569                         K v = t.key(); 
    570                          assert((last is K.init || cmp.compare(last, v) <= 0)); 
     570                         assert((last is K.init || cmp(last, v) <= 0)); 
    571571                         last = v; 
    572572                         t = cast(RBPairT)(t.successor()); 
  • trunk/tango/util/collection/impl/LLCell.d

    r2809 r3358  
    252252                          } 
    253253 
    254                     int diff = cmp.compare(a.element(), b.element()); 
     254                    int diff = cmp (a.element(), b.element()); 
    255255                    if (diff <= 0) 
    256256                       { 
  • trunk/tango/util/collection/impl/RBCell.d

    r2809 r3358  
    270270                for (;;) 
    271271                    { 
    272                     int diff = cmp.compare(element, t.element()); 
     272                    int diff = cmp(element, t.element()); 
    273273                    if (diff is 0) 
    274274                        return t; 
     
    295295                while (t !is null) 
    296296                { 
    297                         int diff = cmp.compare(element, t.element()); 
     297                        int diff = cmp(element, t.element()); 
    298298                        if (diff is 0) 
    299299                        { 
  • trunk/tango/util/collection/impl/RBPair.d

    r2809 r3358  
    153153                for (;;) 
    154154                    { 
    155                     int diff = cmp.compare(key, t.key_); 
     155                    int diff = cmp(key, t.key_); 
    156156                    if (diff is 0) 
    157157                        return t; 
     
    177177                for (;;) 
    178178                    { 
    179                     int diff = cmp.compare(key, t.key_); 
     179                    int diff = cmp(key, t.key_); 
    180180                    if (diff is 0 && t.element() == (element)) 
    181181                        return t; 
     
    202202                while (t !is null) 
    203203                      { 
    204                       int diff = cmp.compare(key, t.key_); 
     204                      int diff = cmp(key, t.key_); 
    205205                      // rely on insert to always go left on <= 
    206206                      if (diff is 0) 
     
    225225                while (t !is null) 
    226226                      { 
    227                       int diff = cmp.compare(key, t.key_); 
     227                      int diff = cmp(key, t.key_); 
    228228                      if (diff is 0) 
    229229                         { 
  • trunk/tango/util/collection/model/Comparator.d

    r2809 r3358  
    2828**/ 
    2929 
     30template Comparator(T) 
     31{ 
     32        alias int delegate(T, T) Comparator; 
     33} 
     34 
     35/+ 
    3036public interface Comparator(T) 
    3137{ 
     
    3844        public int compare(T fst, T snd); 
    3945} 
    40  
     46+/ 
  • trunk/tango/util/collection/model/Sortable.d

    r2809 r3358  
    3333 * obtained in succession from nextElement(), that  
    3434 * <PRE> 
    35  * comparator().compare(a, b) <= 0. 
     35 * comparator(a, b) <= 0. 
    3636 * </PRE> 
    3737 *  
  • trunk/tango/util/collection/model/SortedKeys.d

    r2809 r3358  
    3030 * obtained in succession from keys().nextElement(), that  
    3131 * <PRE> 
    32  * comparator().compare(a, b) <= 0. 
     32 * comparator(a, b) <= 0. 
    3333 * </PRE> 
    3434 *  
  • trunk/tango/util/collection/model/SortedValues.d

    r2809 r3358  
    3131 * obtained in succession from elements().nextElement(), that  
    3232 * <PRE> 
    33  * comparator().compare(a, b) <= 0. 
     33 * comparator(a, b) <= 0. 
    3434 * </PRE> 
    3535 *