Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U0 QuickSortI64(I64 *base, I64 num, I64 (*fp_compare)(I64 e1, I64 e2))
|
2020-02-15 20:01:48 +00:00
|
|
|
{/*Quick Sort for width==8.
|
|
|
|
fp_compare() passes by value instead of ref.
|
|
|
|
|
2020-02-16 03:32:01 +00:00
|
|
|
For ascending strings: return StrCompare(e1,e2);
|
2020-02-20 23:40:10 +00:00
|
|
|
For ascending ints : return e1-e2;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2021-12-11 11:21:22 +00:00
|
|
|
Maybe, look at $LK,"::/Demo/MultiCore/MPRadix.ZC"$.
|
2020-02-15 20:01:48 +00:00
|
|
|
*/
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
I64 i, *left, *right, pivot;
|
|
|
|
|
|
|
|
if (num > 1)
|
|
|
|
{
|
|
|
|
left = base;
|
|
|
|
right = base + num - 1;
|
|
|
|
pivot = base[num / 2];
|
|
|
|
do
|
|
|
|
{
|
|
|
|
while ((*fp_compare)(*left, pivot) < 0)
|
2020-02-20 23:40:10 +00:00
|
|
|
left++;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
while ((*fp_compare)(*right, pivot) > 0)
|
2020-02-20 23:40:10 +00:00
|
|
|
right--;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (left <= right)
|
|
|
|
SwapI64(left++, right--);
|
|
|
|
}
|
|
|
|
while (left <= right);
|
|
|
|
|
|
|
|
i = right + 1 - base;
|
|
|
|
if (1 < i < num)
|
|
|
|
QuickSortI64(base, i, fp_compare);
|
|
|
|
i = base + num - left;
|
|
|
|
if (1 < i < num)
|
|
|
|
QuickSortI64(left, i, fp_compare);
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U0 QuickSort2a(U8 **base, I64 num, I64 (*fp_compare)(U8 **_e1, U8 **_e2))
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Not public.For case of width==size(U8 *)==8.
|
|
|
|
//fp_compare() passes by ref.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
I64 i;
|
|
|
|
U8 **left, **right, *pivot;
|
|
|
|
|
|
|
|
left = base;
|
|
|
|
right = base + num - 1;
|
|
|
|
pivot = base[num / 2];
|
|
|
|
do
|
|
|
|
{
|
|
|
|
while ((*fp_compare)(left, &pivot) < 0)
|
2020-02-20 23:40:10 +00:00
|
|
|
left++;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
while ((*fp_compare)(right, &pivot) > 0)
|
2020-02-20 23:40:10 +00:00
|
|
|
right--;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (left <= right)
|
|
|
|
SwapI64(left++, right--);
|
|
|
|
}
|
|
|
|
while (left <= right);
|
|
|
|
|
|
|
|
i = right + 1 - base;
|
|
|
|
if (1 < i < num)
|
|
|
|
QuickSort2a(base, i, fp_compare);
|
|
|
|
i = base + num - left;
|
|
|
|
if (1 < i < num)
|
|
|
|
QuickSort2a(left, i, fp_compare);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U0 QuickSort2b(U8 *base, I64 num, I64 width, I64 (*fp_compare)(U8 *e1, U8 *e2), U8 *tmp)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Not public
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 i;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U8 *left, *right, *pivot = tmp + width;
|
|
|
|
|
|
|
|
left = base;
|
|
|
|
right = base + (num - 1) * width;
|
|
|
|
MemCopy(pivot, base + num / 2 * width, width);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
while ((*fp_compare)(left, pivot) < 0)
|
|
|
|
left += width;
|
|
|
|
while ((*fp_compare)(right, pivot) > 0)
|
|
|
|
right -= width;
|
|
|
|
if (left <= right)
|
|
|
|
{
|
|
|
|
if (left != right)
|
|
|
|
{
|
|
|
|
MemCopy(tmp, right, width);
|
|
|
|
MemCopy(right, left, width);
|
|
|
|
MemCopy(left, tmp, width);
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
left += width;
|
|
|
|
right -= width;
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
}
|
|
|
|
while (left <= right);
|
|
|
|
|
|
|
|
i = 1 + (right - base) / width;
|
|
|
|
if (1 < i < num)
|
|
|
|
QuickSort2b(base, i, width, fp_compare, tmp);
|
|
|
|
i = num + (base - left) / width;
|
|
|
|
if (1 < i < num)
|
|
|
|
QuickSort2b(left, i, width, fp_compare, tmp);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U0 QuickSort(U8 *base, I64 num, I64 width, I64 (*fp_compare)(U8 *e1, U8 *e2))
|
2020-02-15 20:01:48 +00:00
|
|
|
{/*Quick Sort: fp_compare() passes by ref.
|
|
|
|
|
2020-02-16 03:32:01 +00:00
|
|
|
For ascending strings: return StrCompare(*e1,*e2);
|
2020-02-20 23:40:10 +00:00
|
|
|
For ascending ints : return *e1-*e2;
|
2020-02-15 20:01:48 +00:00
|
|
|
Don't return e1-e2 if numbers can overflow, return -1,0 or 1.
|
|
|
|
|
2021-12-11 11:21:22 +00:00
|
|
|
Maybe, look at $LK,"::/Demo/MultiCore/MPRadix.ZC"$.
|
2020-02-15 20:01:48 +00:00
|
|
|
*/
|
2020-02-20 23:40:10 +00:00
|
|
|
U8 *tmp;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
|
|
|
|
if (width && num > 1)
|
|
|
|
{
|
|
|
|
if (width == sizeof(U8 *)) //assign instead of MemCopy for width 8
|
|
|
|
QuickSort2a(base, num, fp_compare);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = MAlloc(width * 2);
|
|
|
|
QuickSort2b(base, num, width, fp_compare, tmp);
|
2020-02-20 23:40:10 +00:00
|
|
|
Free(tmp);
|
|
|
|
}
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|