diff --git a/libavutil/qsort.h b/libavutil/qsort.h index a9ab1f39ad..089eb74fdf 100644 --- a/libavutil/qsort.h +++ b/libavutil/qsort.h @@ -90,3 +90,28 @@ }\ }\ } + +/** + * Merge sort, this sort requires a temporary buffer and is stable, its worst + * case time is O(n log n) + * @param p must be a lvalue pointer, this function may exchange it with tmp + * @param tmp must be a lvalue pointer, this function may exchange it with p + */ +#define AV_MSORT(p, tmp, num, type, cmp) {\ + unsigned i, j, step;\ + for(step=1; step<(num); step+=step){\ + for(i=0; i<(num); i+=2*step){\ + unsigned a[2] = {i, i+step};\ + unsigned end = FFMIN(i+2*step, (num));\ + for(j=i; a[0]=i+step) a[0] = a[1];\ + for(; j