IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 8, 2008, 12:50:52 PM (18 years ago)
Author:
eugene
Message:

replaced sort functions drived from press with sort macros derived from gsl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/CommandOps.c

    r14449 r16040  
    130130}
    131131
     132void sort_commands (int *seq) {
     133
     134  int i;
     135
     136  for (i = 0; i < Ncommands; i++) seq[i] = i;
     137
     138# define SWAPFUNC(A,B){ int tmp = seq[A]; seq[A] = seq[B]; seq[B] = tmp; }
     139# define COMPARE(A,B)(strcmp (commands[seq[A]].name, commands[seq[B]].name) < 0)
     140
     141  OHANA_SORT (Ncommands, COMPARE, SWAPFUNC);
     142
     143# undef SWAPFUNC
     144# undef COMPARE
     145 
     146}
     147
    132148void print_commands (FILE *f) {
    133149
     
    143159  return;
    144160}
    145 
    146 void sort_commands (int *seq) {
    147 
    148   int l,j,ir,i, N;
    149   int temp;
    150  
    151   N = Ncommands;
    152   for (i = 0; i < N; i++)
    153     seq[i] = i;
    154  
    155   l = N >> 1;
    156   ir = N - 1;
    157   for (;;) {
    158     if (l > 0) {
    159       temp = seq[--l];
    160     }
    161     else {
    162       temp = seq[ir];
    163       seq[ir] = seq[0];
    164       if (--ir == 0) {
    165         seq[0] = temp;
    166         return;
    167       }
    168     }
    169     i = l;
    170     j = (l << 1) + 1;
    171     while (j <= ir) {
    172       if (j < ir && (strcmp (commands[seq[j]].name, commands[seq[j+1]].name) < 0)) ++j;
    173       if (strcmp (commands[temp].name, commands[seq[j]].name) < 0) {
    174         seq[i]=seq[j];
    175         j += (i=j) + 1;
    176       }
    177       else j = ir + 1;
    178     }
    179     seq[i] = temp;
    180   }
    181 }
Note: See TracChangeset for help on using the changeset viewer.