Mercurial > hg > smallbox
annotate DL/RLS-DLA/private/omputils.c @ 63:e08af264ef93
(none)
author | idamnjanovic |
---|---|
date | Tue, 15 Mar 2011 12:23:35 +0000 |
parents | ad36f80e2ccf |
children |
rev | line source |
---|---|
idamnjanovic@60 | 1 /************************************************************************** |
idamnjanovic@60 | 2 * |
idamnjanovic@60 | 3 * File name: omputils.c |
idamnjanovic@60 | 4 * |
idamnjanovic@60 | 5 * Ron Rubinstein |
idamnjanovic@60 | 6 * Computer Science Department |
idamnjanovic@60 | 7 * Technion, Haifa 32000 Israel |
idamnjanovic@60 | 8 * ronrubin@cs |
idamnjanovic@60 | 9 * |
idamnjanovic@60 | 10 * Last Updated: 18.8.2009 |
idamnjanovic@60 | 11 * |
idamnjanovic@60 | 12 *************************************************************************/ |
idamnjanovic@60 | 13 |
idamnjanovic@60 | 14 #include "omputils.h" |
idamnjanovic@60 | 15 #include <math.h> |
idamnjanovic@60 | 16 |
idamnjanovic@60 | 17 |
idamnjanovic@60 | 18 const char FULL_GAMMA_STR[] = "full"; |
idamnjanovic@60 | 19 const char SPARSE_GAMMA_STR[] = "sparse"; |
idamnjanovic@60 | 20 |
idamnjanovic@60 | 21 |
idamnjanovic@60 | 22 /* convert seconds to hours, minutes and seconds */ |
idamnjanovic@60 | 23 |
idamnjanovic@60 | 24 void secs2hms(double sectot, int *hrs, int *mins, double *secs) |
idamnjanovic@60 | 25 { |
idamnjanovic@60 | 26 *hrs = (int)(floor(sectot/3600)+1e-2); |
idamnjanovic@60 | 27 sectot = sectot - 3600*(*hrs); |
idamnjanovic@60 | 28 *mins = (int)(floor(sectot/60)+1e-2); |
idamnjanovic@60 | 29 *secs = sectot - 60*(*mins); |
idamnjanovic@60 | 30 } |
idamnjanovic@60 | 31 |
idamnjanovic@60 | 32 |
idamnjanovic@60 | 33 /* quicksort, public-domain C implementation by Darel Rex Finley. */ |
idamnjanovic@60 | 34 /* modification: sorts the array data[] as well, according to the values in the array vals[] */ |
idamnjanovic@60 | 35 |
idamnjanovic@60 | 36 #define MAX_LEVELS 300 |
idamnjanovic@60 | 37 |
idamnjanovic@60 | 38 void quicksort(mwIndex vals[], double data[], mwIndex n) { |
idamnjanovic@60 | 39 |
idamnjanovic@60 | 40 long piv, beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R, swap ; |
idamnjanovic@60 | 41 double datapiv; |
idamnjanovic@60 | 42 |
idamnjanovic@60 | 43 beg[0]=0; |
idamnjanovic@60 | 44 end[0]=n; |
idamnjanovic@60 | 45 |
idamnjanovic@60 | 46 while (i>=0) { |
idamnjanovic@60 | 47 |
idamnjanovic@60 | 48 L=beg[i]; |
idamnjanovic@60 | 49 R=end[i]-1; |
idamnjanovic@60 | 50 |
idamnjanovic@60 | 51 if (L<R) { |
idamnjanovic@60 | 52 |
idamnjanovic@60 | 53 piv=vals[L]; |
idamnjanovic@60 | 54 datapiv=data[L]; |
idamnjanovic@60 | 55 |
idamnjanovic@60 | 56 while (L<R) |
idamnjanovic@60 | 57 { |
idamnjanovic@60 | 58 while (vals[R]>=piv && L<R) |
idamnjanovic@60 | 59 R--; |
idamnjanovic@60 | 60 if (L<R) { |
idamnjanovic@60 | 61 vals[L]=vals[R]; |
idamnjanovic@60 | 62 data[L++]=data[R]; |
idamnjanovic@60 | 63 } |
idamnjanovic@60 | 64 |
idamnjanovic@60 | 65 while (vals[L]<=piv && L<R) |
idamnjanovic@60 | 66 L++; |
idamnjanovic@60 | 67 if (L<R) { |
idamnjanovic@60 | 68 vals[R]=vals[L]; |
idamnjanovic@60 | 69 data[R--]=data[L]; |
idamnjanovic@60 | 70 } |
idamnjanovic@60 | 71 } |
idamnjanovic@60 | 72 |
idamnjanovic@60 | 73 vals[L]=piv; |
idamnjanovic@60 | 74 data[L]=datapiv; |
idamnjanovic@60 | 75 |
idamnjanovic@60 | 76 beg[i+1]=L+1; |
idamnjanovic@60 | 77 end[i+1]=end[i]; |
idamnjanovic@60 | 78 end[i++]=L; |
idamnjanovic@60 | 79 |
idamnjanovic@60 | 80 if (end[i]-beg[i] > end[i-1]-beg[i-1]) { |
idamnjanovic@60 | 81 swap=beg[i]; beg[i]=beg[i-1]; beg[i-1]=swap; |
idamnjanovic@60 | 82 swap=end[i]; end[i]=end[i-1]; end[i-1]=swap; |
idamnjanovic@60 | 83 } |
idamnjanovic@60 | 84 } |
idamnjanovic@60 | 85 else { |
idamnjanovic@60 | 86 i--; |
idamnjanovic@60 | 87 } |
idamnjanovic@60 | 88 } |
idamnjanovic@60 | 89 } |