761 Int32 i, j, k, ss, sb;
762 Int32 runningOrder[256];
764 Int32 copyStart[256];
769 if (verb >= 4)
VPrintf0 (
" main sort initialise ...\n" );
772 for (i = 65536; i >= 0; i--) ftab[i] = 0;
776 for (; i >= 3; i -= 4) {
778 j = (j >> 8) | ( ((
UInt16)block[i]) << 8);
781 j = (j >> 8) | ( ((
UInt16)block[i-1]) << 8);
784 j = (j >> 8) | ( ((
UInt16)block[i-2]) << 8);
787 j = (j >> 8) | ( ((
UInt16)block[i-3]) << 8);
790 for (; i >= 0; i--) {
792 j = (j >> 8) | ( ((
UInt16)block[i]) << 8);
798 block [nblock+i] = block[i];
799 quadrant[nblock+i] = 0;
802 if (verb >= 4)
VPrintf0 (
" bucket sorting ...\n" );
805 for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
809 for (; i >= 3; i -= 4) {
810 s = (s >> 8) | (block[i] << 8);
814 s = (s >> 8) | (block[i-1] << 8);
818 s = (s >> 8) | (block[i-2] << 8);
822 s = (s >> 8) | (block[i-3] << 8);
827 for (; i >= 0; i--) {
828 s = (s >> 8) | (block[i] << 8);
839 for (i = 0; i <= 255; i++) {
847 do h = 3 * h + 1;
while (h <= 256);
850 for (i = h; i <= 255; i++) {
851 vv = runningOrder[i];
854 runningOrder[j] = runningOrder[j-h];
856 if (j <= (h - 1))
goto zero;
859 runningOrder[j] = vv;
870 for (i = 0; i <= 255; i++) {
878 ss = runningOrder[i];
888 for (j = 0; j <= 255; j++) {
891 if ( ! (ftab[sb] &
SETMASK) ) {
898 ss, j, numQSorted, hi - lo + 1 );
900 ptr, block, quadrant, nblock,
903 numQSorted += (hi - lo + 1);
904 if (*budget < 0)
return;
911 AssertH ( !bigDone[ss], 1006 );
921 for (j = 0; j <= 255; j++) {
922 copyStart[j] = ftab[(j << 8) + ss] & CLEARMASK;
923 copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
925 for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
926 k = ptr[j]-1;
if (k < 0) k += nblock;
929 ptr[ copyStart[c1]++ ] = k;
931 for (j = (ftab[(ss+1) << 8] &
CLEARMASK) - 1; j > copyEnd[ss]; j--) {
932 k = ptr[j]-1;
if (k < 0) k += nblock;
935 ptr[ copyEnd[c1]-- ] = k;
939 AssertH ( (copyStart[ss]-1 == copyEnd[ss])
945 (copyStart[ss] == 0 && copyEnd[ss] == nblock-1),
948 for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= SETMASK;
993 Int32 bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
996 while ((bbSize >> shifts) > 65534) shifts++;
998 for (j = bbSize-1; j >= 0; j--) {
999 Int32 a2update = ptr[bbStart + j];
1001 quadrant[a2update] = qVal;
1002 if (a2update < BZ_N_OVERSHOOT)
1003 quadrant[a2update + nblock] = qVal;
1005 AssertH ( ((bbSize-1) >> shifts) <= 65535, 1002 );
1011 VPrintf3 (
" %d pointers, %d sorted, %d scanned\n",
1012 nblock, numQSorted, nblock - numQSorted );
for(p=first;p->value< newval;p=p->next)
#define AssertH(cond, errcode)
#define VPrintf3(zf, za1, za2, za3)
#define VPrintf4(zf, za1, za2, za3, za4)
static void mainQSort3(UInt32 *ptr, UChar *block, UInt16 *quadrant, Int32 nblock, Int32 loSt, Int32 hiSt, Int32 dSt, Int32 *budget)