6 SDSortCompareCallback
*comp
;
7 SDSortSwapCallback
*swap
;
10 int Sorting_isSorted(SDSort
*self
, size_t size
);
11 void Sorting_quickSort(SDSort
*self
, size_t lb
, size_t ub
);
12 int Sorting_quickSortRearrange(SDSort
*self
, size_t lb
, size_t ub
);
14 void Sorting_context_comp_swap_size_type_(void *context
,
15 SDSortCompareCallback
*comp
,
16 SDSortSwapCallback
*swap
,
23 self
->context
= context
;
30 if (!Sorting_isSorted(self
, size
)) Sorting_quickSort(self
, 0, size
-1);
35 int Sorting_isSorted(SDSort
*self
, size_t size
)
37 SDSortCompareCallback
*comp
= self
->comp
;
38 void *context
= self
->context
;
41 for (i
= 0; i
+ 1 < size
; i
++)
43 if ((*comp
)(context
, i
, i
+ 1) > 0)
52 void Sorting_quickSort(SDSort
*self
, size_t lb
, size_t ub
)
56 int j
= Sorting_quickSortRearrange(self
, lb
, ub
);
60 Sorting_quickSort(self
, lb
, j
- 1);
63 Sorting_quickSort(self
, j
+ 1, ub
);
67 int Sorting_quickSortRearrange(SDSort
*self
, size_t lb
, size_t ub
)
69 SDSortCompareCallback
*comp
= self
->comp
;
70 SDSortSwapCallback
*swap
= self
->swap
;
71 void *context
= self
->context
;
74 while (ub
> lb
&& (*comp
)(context
, ub
, lb
) >= 0)
81 (*swap
)(context
, ub
, lb
);
83 while (lb
< ub
&& (*comp
)(context
, lb
, ub
) <= 0)
90 (*swap
)(context
, lb
, ub
);