⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbzip2outputstream.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        }        /* Now the selectors. */        nBytes = bytesOut;        bsW (3, nGroups);        bsW (15, nSelectors);        for (i = 0; i < nSelectors; i++) {            for (j = 0; j < selectorMtf[i]; j++) {                bsW(1, 1);            }            bsW(1, 0);        }        /* Now the coding tables. */        nBytes = bytesOut;        for (t = 0; t < nGroups; t++) {            int curr = len[t][0];            bsW(5, curr);            for (i = 0; i < alphaSize; i++) {                while (curr < len[t][i]) {                    bsW(2, 2);                    curr++; /* 10 */                }                while (curr > len[t][i]) {                    bsW(2, 3);                    curr--; /* 11 */                }                bsW (1, 0);            }        }        /* And finally, the block data proper */        nBytes = bytesOut;        selCtr = 0;        gs = 0;        while (true) {            if (gs >= nMTF) {                break;            }            ge = gs + G_SIZE - 1;            if (ge >= nMTF) {                ge = nMTF - 1;            }            for (i = gs; i <= ge; i++) {                bsW(len[selector[selCtr]][szptr[i]],                    code[selector[selCtr]][szptr[i]]);            }            gs = ge + 1;            selCtr++;        }        if (!(selCtr == nSelectors)) {            panic();        }    }    private void moveToFrontCodeAndSend () throws IOException {        bsPutIntVS(24, origPtr);        generateMTFValues();        sendMTFValues();    }    private OutputStream bsStream;    private void simpleSort(int lo, int hi, int d) {        int i, j, h, bigN, hp;        int v;        bigN = hi - lo + 1;        if (bigN < 2) {            return;        }        hp = 0;        while (incs[hp] < bigN) {            hp++;        }        hp--;        for (; hp >= 0; hp--) {            h = incs[hp];            i = lo + h;            while (true) {                /* copy 1 */                if (i > hi) {                    break;                }                v = zptr[i];                j = i;                while (fullGtU(zptr[j - h] + d, v + d)) {                    zptr[j] = zptr[j - h];                    j = j - h;                    if (j <= (lo + h - 1)) {                        break;                    }                }                zptr[j] = v;                i++;                /* copy 2 */                if (i > hi) {                    break;                }                v = zptr[i];                j = i;                while (fullGtU(zptr[j - h] + d, v + d)) {                    zptr[j] = zptr[j - h];                    j = j - h;                    if (j <= (lo + h - 1)) {                        break;                    }                }                zptr[j] = v;                i++;                /* copy 3 */                if (i > hi) {                    break;                }                v = zptr[i];                j = i;                while (fullGtU(zptr[j - h] + d, v + d)) {                    zptr[j] = zptr[j - h];                    j = j - h;                    if (j <= (lo + h - 1)) {                        break;                    }                }                zptr[j] = v;                i++;                if (workDone > workLimit && firstAttempt) {                    return;                }            }        }    }    private void vswap(int p1, int p2, int n) {        int temp = 0;        while (n > 0) {            temp = zptr[p1];            zptr[p1] = zptr[p2];            zptr[p2] = temp;            p1++;            p2++;            n--;        }    }    private char med3(char a, char b, char c) {        char t;        if (a > b) {            t = a;            a = b;            b = t;        }        if (b > c) {            t = b;            b = c;            c = t;        }        if (a > b) {            b = a;        }        return b;    }    private static class StackElem {        int ll;        int hh;        int dd;    }    private void qSort3(int loSt, int hiSt, int dSt) {        int unLo, unHi, ltLo, gtHi, med, n, m;        int sp, lo, hi, d;        StackElem[] stack = new StackElem[QSORT_STACK_SIZE];        for (int count = 0; count < QSORT_STACK_SIZE; count++) {            stack[count] = new StackElem();        }        sp = 0;        stack[sp].ll = loSt;        stack[sp].hh = hiSt;        stack[sp].dd = dSt;        sp++;        while (sp > 0) {            if (sp >= QSORT_STACK_SIZE) {                panic();            }            sp--;            lo = stack[sp].ll;            hi = stack[sp].hh;            d = stack[sp].dd;            if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) {                simpleSort(lo, hi, d);                if (workDone > workLimit && firstAttempt) {                    return;                }                continue;            }            med = med3(block[zptr[lo] + d + 1],                       block[zptr[hi            ] + d  + 1],                       block[zptr[(lo + hi) >> 1] + d + 1]);            unLo = ltLo = lo;            unHi = gtHi = hi;            while (true) {                while (true) {                    if (unLo > unHi) {                        break;                    }                    n = ((int) block[zptr[unLo] + d + 1]) - med;                    if (n == 0) {                        int temp = 0;                        temp = zptr[unLo];                        zptr[unLo] = zptr[ltLo];                        zptr[ltLo] = temp;                        ltLo++;                        unLo++;                        continue;                    };                    if (n >  0) {                        break;                    }                    unLo++;                }                while (true) {                    if (unLo > unHi) {                        break;                    }                    n = ((int) block[zptr[unHi] + d + 1]) - med;                    if (n == 0) {                        int temp = 0;                        temp = zptr[unHi];                        zptr[unHi] = zptr[gtHi];                        zptr[gtHi] = temp;                        gtHi--;                        unHi--;                        continue;                    };                    if (n <  0) {                        break;                    }                    unHi--;                }                if (unLo > unHi) {                    break;                }                int temp = 0;                temp = zptr[unLo];                zptr[unLo] = zptr[unHi];                zptr[unHi] = temp;                unLo++;                unHi--;            }            if (gtHi < ltLo) {                stack[sp].ll = lo;                stack[sp].hh = hi;                stack[sp].dd = d + 1;                sp++;                continue;            }            n = ((ltLo - lo) < (unLo - ltLo)) ? (ltLo - lo) : (unLo - ltLo);            vswap(lo, unLo - n, n);            m = ((hi - gtHi) < (gtHi - unHi)) ? (hi - gtHi) : (gtHi - unHi);            vswap(unLo, hi - m + 1, m);            n = lo + unLo - ltLo - 1;            m = hi - (gtHi - unHi) + 1;            stack[sp].ll = lo;            stack[sp].hh = n;            stack[sp].dd = d;            sp++;            stack[sp].ll = n + 1;            stack[sp].hh = m - 1;            stack[sp].dd = d + 1;            sp++;            stack[sp].ll = m;            stack[sp].hh = hi;            stack[sp].dd = d;            sp++;        }    }    private void mainSort() {        int i, j, ss, sb;        int[] runningOrder = new int[256];        int[] copy = new int[256];        boolean[] bigDone = new boolean[256];        int c1, c2;        int numQSorted;        /*          In the various block-sized structures, live data runs          from 0 to last+NUM_OVERSHOOT_BYTES inclusive.  First,          set up the overshoot area for block.        */        //   if (verbosity >= 4) fprintf ( stderr, "   sort initialise ...\n" );        for (i = 0; i < NUM_OVERSHOOT_BYTES; i++) {            block[last + i + 2] = block[(i % (last + 1)) + 1];        }        for (i = 0; i <= last + NUM_OVERSHOOT_BYTES; i++) {            quadrant[i] = 0;        }        block[0] = (char) (block[last + 1]);        if (last < 4000) {            /*              Use simpleSort(), since the full sorting mechanism              has quite a large constant overhead.            */            for (i = 0; i <= last; i++) {                zptr[i] = i;            }            firstAttempt = false;            workDone = workLimit = 0;            simpleSort(0, last, 0);        } else {            numQSorted = 0;            for (i = 0; i <= 255; i++) {                bigDone[i] = false;            }            for (i = 0; i <= 65536; i++) {                ftab[i] = 0;            }            c1 = block[0];            for (i = 0; i <= last; i++) {                c2 = block[i + 1];                ftab[(c1 << 8) + c2]++;                c1 = c2;            }            for (i = 1; i <= 65536; i++) {                ftab[i] += ftab[i - 1];            }            c1 = block[1];            for (i = 0; i < last; i++) {                c2 = block[i + 2];                j = (c1 << 8) + c2;                c1 = c2;                ftab[j]--;                zptr[ftab[j]] = i;            }            j = ((block[last + 1]) << 8) + (block[1]);            ftab[j]--;            zptr[ftab[j]] = last;            /*              Now ftab contains the first loc of every small bucket.              Calculate the running order, from smallest to largest              big bucket.            */            for (i = 0; i <= 255; i++) {                runningOrder[i] = i;            }            {                int vv;                int h = 1;                do {                    h = 3 * h + 1;                }                while (h <= 256);                do {                    h = h / 3;                    for (i = h; i <= 255; i++) {                        vv = runningOrder[i];                        j = i;                        while ((ftab[((runningOrder[j - h]) + 1) << 8]                                - ftab[(runningOrder[j - h]) << 8])                                > (ftab[((vv) + 1) << 8] - ftab[(vv) << 8])) {                            runningOrder[j] = runningOrder[j - h];                            j = j - h;                            if (j <= (h - 1)) {                                break;                            }                        }                        runningOrder[j] = vv;                    }                } while (h != 1);            }            /*              The main sorting loop.            */            for (i = 0; i <= 255; i++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -