Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBsortS.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include "CTBgrab.hxx"
00015 
00025 
00026 
00027 template <class T, class C>
00028 inline void CTBsortS<T,C>::operator()(CTBvector<T>& v)
00029 {
00030   CTBgrab<T>  grab;
00031   C           compare;
00032   T           tmp;
00033 
00034   for (CTBint m = v.Size()/2; m > 0; m = m/2) {
00035 
00036     for (CTBint i = m; i < v.Size(); i++) {
00037       grab(tmp,v[i]);
00038       CTBint j = i-m;
00039       
00040       while (j >= 0 && compare(tmp,v[j])) {
00041         grab(v[j+m],v[j]);
00042         j -= m;
00043       }
00044       grab(v[j+m],tmp);
00045     }
00046   }
00047   
00048   return;
00049 }
00050 
00051 // Note:
00052 //  1. This implementation was inspired by the one given in Numerical Recipes
00053 //     in C, Chapter 8.1
00054 
00055 //------------------------------------------+-----------------------------------
00057 
00058 template <class T, class C>
00059 inline void CTBsortS<T,C>::operator()(CTBvector<CTBint>& ind,
00060                                       const CTBvector<T>& v)
00061 {
00062   C      compare;
00063   
00064   ind.Resize(v.Size());
00065   for (CTBint i = 0; i < v.Size(); i++) ind[i] = i;
00066   
00067   for (CTBint m = v.Size()/2; m > 0; m = m/2) {
00068 
00069     for (CTBint i = m; i < v.Size(); i++) {
00070       CTBint tmp = ind[i];
00071       CTBint j   = i-m;
00072       
00073       while (j >= 0 && compare(v[tmp],v[ind[j]])) {
00074         ind[j+m] = ind[j];
00075         j -= m;
00076       }
00077       ind[j+m] = tmp;
00078     }
00079   }
00080   
00081   return;
00082 }

Generated at Fri Oct 24 18:11:30 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001