From 949dc1f78744da787f21f740118662fb20db3d42 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sat, 16 Aug 2014 12:52:13 -0500 Subject: Delete portions of grailsort reference code we're not using There's a lot of code in here that works with an externally provided extra buffer, but because we're not testing with that, it unfairly skews the code size against this algorithm. --- grailsort_ref.c | 155 +++++++------------------------------------------------- 1 file changed, 19 insertions(+), 136 deletions(-) (limited to 'grailsort_ref.c') diff --git a/grailsort_ref.c b/grailsort_ref.c index 0a95076..b2c53f4 100644 --- a/grailsort_ref.c +++ b/grailsort_ref.c @@ -19,8 +19,6 @@ #define SORT_TYPE int static cmpfun SORT_CMP; -#define GRAIL_EXT_BUFFER_LENGTH 512 - static inline void grail_swap1(SORT_TYPE *a,SORT_TYPE *b){ SORT_TYPE c=*a; *a=*b; @@ -177,126 +175,22 @@ static void grail_SmartMergeWithoutBuffer(SORT_TYPE *arr,int *alen1,int *atype,i *alen1=len2; *atype=ftype; } -/***** Sort With Extra Buffer *****/ - -// arr[M..-1] - free, arr[0,L1-1]++arr[L1,L1+L2-1] -> arr[M,M+L1+L2-1] -static void grail_MergeLeftWithXBuf(SORT_TYPE *arr,int L1,int L2,int M){ - int p0=0,p1=L1; L2+=L1; - while(p10) arr[M++]=arr[p1++]; - else arr[M++]=arr[p0++]; - } - if(M!=p0) while(p00, nblock2=0 is possible. -static void grail_MergeBuffersLeftWithXBuf(SORT_TYPE *keys,SORT_TYPE *midkey,SORT_TYPE *arr,int nblock,int lblock,int nblock2,int llast){ - int l,prest,lrest,frest,pidx,cidx,fnext,plast; - - if(nblock==0){ - l=nblock2*lblock; - grail_MergeLeftWithXBuf(arr,l,llast,-lblock); - return; - } - - lrest=lblock; - frest=SORT_CMP(keys,midkey)<0 ? 0 : 1; - pidx=lblock; - for(cidx=1;cidx0) u=1; - arr[m-3]=arr[m-1+u]; - arr[m-2]=arr[m-u]; - } - if(L%2) arr[L-3]=arr[L-1]; - arr-=2; - for(h=2;hh){ - grail_MergeLeftWithXBuf(arr+p0,h,rest-h,-h); - } else { - for(;p00) u=1; - grail_swap1(arr+(m-3),arr+(m-1+u)); - grail_swap1(arr+(m-2),arr+(m-u)); - } - if(L%2) grail_swap1(arr+(L-1),arr+(L-3)); - arr-=2; - h=2; + for(m=1;m0) u=1; + grail_swap1(arr+(m-3),arr+(m-1+u)); + grail_swap1(arr+(m-2),arr+(m-u)); } + if(L%2) grail_swap1(arr+(L-1),arr+(L-3)); + arr-=2; + h=2; + for(;h=0;) arr[p]=arr[p-lblock]; - memcpy(arr-lblock,xbuf,lblock*sizeof(SORT_TYPE)); - }else if(havebuf) while(--len>=0) grail_swap1(arr+len,arr+len-lblock); + if(havebuf) while(--len>=0) grail_swap1(arr+len,arr+len-lblock); } -static void grail_commonSort(SORT_TYPE *arr,int Len,SORT_TYPE *extbuf,int LExtBuf){ +static void grail_commonSort(SORT_TYPE *arr,int Len){ int lblock,nkeys,findkeys,ptr,cbuf,lb,nk; bool havebuf,chavebuf; long long s; @@ -471,8 +361,7 @@ static void grail_commonSort(SORT_TYPE *arr,int Len,SORT_TYPE *extbuf,int LExtBu } ptr=lblock+nkeys; cbuf=havebuf ? lblock : nkeys; - if(havebuf) grail_BuildBlocks(arr+ptr,Len-ptr,cbuf,extbuf,LExtBuf); - else grail_BuildBlocks(arr+ptr,Len-ptr,cbuf,NULL,0); + grail_BuildBlocks(arr+ptr,Len-ptr,cbuf); // 2*cbuf are built while(Len-ptr>(cbuf*=2)){ @@ -490,21 +379,15 @@ static void grail_commonSort(SORT_TYPE *arr,int Len,SORT_TYPE *extbuf,int LExtBu } lb=(2*cbuf)/nk; } - } else{ -#if 0 - if(LExtBuf!=0){ - while(lb>LExtBuf && lb*lb>2*cbuf) lb/=2; // set size of block close to sqrt(new_block_length) - } -#endif } - grail_CombineBlocks(arr,arr+ptr,Len-ptr,cbuf,lb,chavebuf,chavebuf && lb<=LExtBuf ? extbuf : NULL); + grail_CombineBlocks(arr,arr+ptr,Len-ptr,cbuf,lb,chavebuf); } grail_SortIns(arr,ptr); grail_MergeWithoutBuffer(arr,ptr,Len-ptr); } static void GrailSort(SORT_TYPE *arr,int Len){ - grail_commonSort(arr,Len,NULL,0); + grail_commonSort(arr,Len); } void grailsort_ref(void *base, size_t nmel, size_t width, cmpfun cmp) -- cgit v1.2.3