Commit dfa9e2c5 authored by Yunqing Wang's avatar Yunqing Wang Committed by Code Review
Browse files

Merge "Use insertion sort instead of quick sort"

parents 1b2abc5f 5abafcc3
...@@ -1432,85 +1432,54 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x, ...@@ -1432,85 +1432,54 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
return bsi.segment_rd; return bsi.segment_rd;
} }
static void swap(int *x,int *y) static void insertsortmv(int arr[], int len)
{ {
int tmp; int i, j, k;
tmp = *x;
*x = *y;
*y = tmp;
}
static void quicksortmv(int arr[],int left, int right)
{
int lidx,ridx,pivot;
lidx = left;
ridx = right;
if( left < right) for ( i = 1 ; i <= len-1 ; i++ )
{ {
pivot = (left + right)/2; for ( j = 0 ; j < i ; j++ )
while(lidx <=pivot && ridx >=pivot)
{ {
while(arr[lidx] < arr[pivot] && lidx <= pivot) if ( arr[j] > arr[i] )
lidx++;
while(arr[ridx] > arr[pivot] && ridx >= pivot)
ridx--;
swap(&arr[lidx], &arr[ridx]);
lidx++;
ridx--;
if(lidx-1 == pivot)
{ {
ridx++; int temp;
pivot = ridx;
} temp = arr[i];
else if(ridx+1 == pivot)
{ for ( k = i; k >j; k--)
lidx--; arr[k] = arr[k - 1] ;
pivot = lidx;
arr[j] = temp ;
} }
} }
quicksortmv(arr, left, pivot - 1);
quicksortmv(arr, pivot + 1, right);
} }
} }
static void quicksortsad(int arr[],int idx[], int left, int right) static void insertsortsad(int arr[],int idx[], int len)
{ {
int lidx,ridx,pivot; int i, j, k;
lidx = left;
ridx = right;
if( left < right) for ( i = 1 ; i <= len-1 ; i++ )
{ {
pivot = (left + right)/2; for ( j = 0 ; j < i ; j++ )
while(lidx <=pivot && ridx >=pivot)
{ {
while(arr[lidx] < arr[pivot] && lidx <= pivot) if ( arr[j] > arr[i] )
lidx++;
while(arr[ridx] > arr[pivot] && ridx >= pivot)
ridx--;
swap(&arr[lidx], &arr[ridx]);
swap(&idx[lidx], &idx[ridx]);
lidx++;
ridx--;
if(lidx-1 == pivot)
{ {
ridx++; int temp, tempi;
pivot = ridx;
} temp = arr[i];
else if(ridx+1 == pivot) tempi = idx[i];
for ( k = i; k >j; k--)
{ {
lidx--; arr[k] = arr[k - 1] ;
pivot = lidx; idx[k] = idx[k - 1];
}
arr[j] = temp ;
idx[j] = tempi;
} }
} }
quicksortsad(arr, idx, left, pivot - 1);
quicksortsad(arr, idx, pivot + 1, right);
} }
} }
...@@ -1647,8 +1616,8 @@ void vp8_mv_pred ...@@ -1647,8 +1616,8 @@ void vp8_mv_pred
mvy[i] = near_mvs[i].as_mv.col; mvy[i] = near_mvs[i].as_mv.col;
} }
quicksortmv (mvx, 0, vcnt-1); insertsortmv(mvx, vcnt);
quicksortmv (mvy, 0, vcnt-1); insertsortmv(mvy, vcnt);
mv.as_mv.row = mvx[vcnt/2]; mv.as_mv.row = mvx[vcnt/2];
mv.as_mv.col = mvy[vcnt/2]; mv.as_mv.col = mvy[vcnt/2];
...@@ -1711,10 +1680,10 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse ...@@ -1711,10 +1680,10 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse
if(cpi->common.last_frame_type != KEY_FRAME) if(cpi->common.last_frame_type != KEY_FRAME)
{ {
quicksortsad(near_sad, near_sadidx, 0, 7); insertsortsad(near_sad, near_sadidx, 8);
}else }else
{ {
quicksortsad(near_sad, near_sadidx, 0, 2); insertsortsad(near_sad, near_sadidx, 3);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment