Mercurial > hg > Game > Cerium
diff example/many_task/ppe/QuickSort.cc @ 1508:0e1318e7caed draft
create sort test
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Sep 2012 18:59:54 +0900 |
parents | 704b9e320f1e |
children | 18b63e697c61 |
line wrap: on
line diff
--- a/example/many_task/ppe/QuickSort.cc Mon Sep 10 17:03:39 2012 +0900 +++ b/example/many_task/ppe/QuickSort.cc Tue Sep 18 18:59:54 2012 +0900 @@ -9,7 +9,7 @@ static void swap( Data *data, int left, int right ) { - Data tmp = data[left]; + Data tmp = data[left]; data[left] = data[right]; data[right] = tmp; } @@ -19,7 +19,7 @@ static int run(SchedTask *s, void* rbuff, void* wbuff) { // copy value - int begin = 0; + int begin = 0; #if USE_SIMPLE_TASK int end = s->read_size()/sizeof(Data); Data *r_data = (Data*)rbuff; @@ -35,10 +35,10 @@ #endif // printf("[PPE] Quick: length:%d addr->%x \n",end, (int)rbuff); - // printf("[PPE] Quick: data[0]: %ld addr->%lx\n",sizeof(r_data),(long)r_data); + // printf("[PPE] Quick: data[0]: %ld addr->%lx\n",sizeof(r_data),(long)r_data); - //show_data(r_data, end); quick_sort(r_data, begin, end-1); + #ifdef USE_MEMCPY memcpy(w_data, r_data, sizeof(Data)*end); #else @@ -48,26 +48,32 @@ return 0; } -static void -quick_sort( Data *data, int begin, int end ) { +void +qsort_test(Data *data, int begin, int end ) { + quick_sort(data, begin, end); + printf("end is %d\n",end); +} + +static void +quick_sort(Data *data, int begin, int end ) { if (begin < end) { - int where = (begin + end) / 2; - int pivot = data[where].index; - data[where].index = data[begin].index; - int p = begin; - int i; - for (i=begin+1; i<=end; i++) { - if (data[i].index < pivot) { - p++; - swap(data, p, i); - } - } - data[begin].index = data[p].index; - data[p].index = pivot; - - quick_sort(data, begin, p-1); - quick_sort(data, p+1, end); // tail call + int where = (begin + end) / 2; + int pivot = data[where].index; + data[where].index = data[begin].index; + int p = begin; + int i; + for (i=begin+1; i<end; i++) { + if (data[i].index < pivot) { + p++; + swap(data, p, i); + } + } + data[begin].index = data[p].index; + data[p].index = pivot; + + quick_sort(data, begin, p-1); + quick_sort(data, p+1, end); // tail call } }