Go to the documentation of this file.
30 #define AV_QSORT(p, num, type, cmp) {\
34 stack[0][1] = (p)+(num)-1;\
36 type *start= stack[--sp][0];\
37 type *end = stack[ sp][1];\
42 type *left = start+1;\
43 type *mid = start + ((end-start)>>1);\
44 if(cmp(start, end) > 0) {\
45 if(cmp( end, mid) > 0) FFSWAP(type, *start, *mid);\
46 else FFSWAP(type, *start, *end);\
48 if(cmp(start, mid) > 0) FFSWAP(type, *start, *mid);\
51 if(cmp(mid, end) > 0){ \
52 FFSWAP(type, *mid, *end);\
55 if(start == end-2) break;\
56 FFSWAP(type, end[-1], *mid);\
57 while(left <= right){\
58 while(left<=right && cmp(left, end-1) < 0)\
60 while(left<=right && cmp(right, end-1) > 0)\
63 FFSWAP(type, *left, *right);\
68 FFSWAP(type, end[-1], *left);\
69 if(checksort && (mid == left-1 || mid == left)){\
71 while(mid<end && cmp(mid, mid+1) <= 0)\
76 if(end-left < left-start){\
77 stack[sp ][0]= start;\
78 stack[sp++][1]= right;\
81 stack[sp ][0]= left+1;\
86 if(cmp(start, end) > 0)\
87 FFSWAP(type, *start, *end);\
100 #define AV_MSORT(p, tmp, num, type, cmp) {\
101 unsigned i, j, step;\
102 for(step=1; step<(num); step+=step){\
103 for(i=0; i<(num); i+=2*step){\
104 unsigned a[2] = {i, i+step};\
105 unsigned end = FFMIN(i+2*step, (num));\
106 for(j=i; a[0]<i+step && a[1]<end; j++){\
107 int idx= cmp(p+a[0], p+a[1]) > 0;\
108 tmp[j] = p[ a[idx]++ ];\
110 if(a[0]>=i+step) a[0] = a[1];\
112 tmp[j] = p[ a[0]++ ];\
115 FFSWAP(type*, p, tmp);\