private void blockSort() { blockSorter.blockSort(data, last); }
void blockSort(final BZip2CompressorOutputStream.Data data, final int last) { this.workLimit = WORK_FACTOR * last; this.workDone = 0; this.firstAttempt = true; if (last + 1 < 10000) { fallbackSort(data, last); } else { mainSort(data, last); if (this.firstAttempt && (this.workDone > this.workLimit)) { fallbackSort(data, last); } } final int[] fmap = data.fmap; data.origPtr = -1; for (int i = 0; i <= last; i++) { if (fmap[i] == 0) { data.origPtr = i; break; } } // assert (data.origPtr != -1) : data.origPtr; }
/** * swaps two intervals starting at yyp1 and yyp2 of length yyn inside fmap. */ private void fvswap(int[] fmap, int yyp1, int yyp2, int yyn) { while (yyn > 0) { fswap(fmap, yyp1, yyp2); yyp1++; yyp2++; yyn--; } }
fpush(sp++, loSt, hiSt); int[] s = fpop(--sp); lo = s[0]; hi = s[1]; fallbackSimpleSort(fmap, eclass, lo, hi); continue; fswap(fmap, unLo, ltLo); ltLo++; unLo++; continue; fswap(fmap, unHi, gtHi); gtHi--; unHi--; continue; fswap(fmap, unLo, unHi); unLo++; unHi--; n = fmin(ltLo - lo, unLo - ltLo); fvswap(fmap, lo, unLo - n, n); int m = fmin(hi - gtHi, gtHi - unHi); fvswap(fmap, unHi + 1, hi - m + 1, m); fpush(sp++, lo, n); fpush(sp++, m, hi); } else { fpush(sp++, m, hi); fpush(sp++, lo, n);
int nNotDone; int nBhtab; final int[] eclass = getEclass(); fallbackQSort3(fmap, eclass, l, r);
/** * Adapt fallbackSort to the expected interface of the rest of the * code, in particular deal with the fact that block starts at * offset 1 (in libbzip2 1.0.6 it starts at 0). */ final void fallbackSort(final BZip2CompressorOutputStream.Data data, final int last) { data.block[0] = data.block[last + 1]; fallbackSort(data.fmap, data.block, last + 1); for (int i = 0; i < last + 1; i++) { --data.fmap[i]; } for (int i = 0; i < last + 1; i++) { if (data.fmap[i] == -1) { data.fmap[i] = last; break; } } }
/** * Writes magic bytes like BZ on the first position of the stream * and bytes indiciating the file-format, which is * huffmanised, followed by a digit indicating blockSize100k. * @throws IOException if the magic bytes could not been written */ private void init() throws IOException { bsPutUByte('B'); bsPutUByte('Z'); this.data = new Data(this.blockSize100k); this.blockSorter = new BlockSort(this.data); // huffmanised magic bytes bsPutUByte('h'); bsPutUByte('0' + this.blockSize100k); this.combinedCRC = 0; initBlock(); }
fpush(sp++, loSt, hiSt); int[] s = fpop(--sp); lo = s[0]; hi = s[1]; fallbackSimpleSort(fmap, eclass, lo, hi); continue; fswap(fmap, unLo, ltLo); ltLo++; unLo++; continue; fswap(fmap, unHi, gtHi); gtHi--; unHi--; continue; fswap(fmap, unLo, unHi); unLo++; unHi--; n = fmin(ltLo - lo, unLo - ltLo); fvswap(fmap, lo, unLo - n, n); int m = fmin(hi - gtHi, gtHi - unHi); fvswap(fmap, unHi + 1, hi - m + 1, m); fpush(sp++, lo, n); fpush(sp++, m, hi); } else { fpush(sp++, m, hi); fpush(sp++, lo, n);
int nNotDone; int nBhtab; final int[] eclass = getEclass(); fallbackQSort3(fmap, eclass, l, r);
/** * Adapt fallbackSort to the expected interface of the rest of the * code, in particular deal with the fact that block starts at * offset 1 (in libbzip2 1.0.6 it starts at 0). */ final void fallbackSort(final BZip2CompressorOutputStream.Data data, final int last) { data.block[0] = data.block[last + 1]; fallbackSort(data.fmap, data.block, last + 1); for (int i = 0; i < last + 1; i++) { --data.fmap[i]; } for (int i = 0; i < last + 1; i++) { if (data.fmap[i] == -1) { data.fmap[i] = last; break; } } }
/** * Writes magic bytes like BZ on the first position of the stream * and bytes indiciating the file-format, which is * huffmanised, followed by a digit indicating blockSize100k. * @throws IOException if the magic bytes could not been written */ private void init() throws IOException { bsPutUByte('B'); bsPutUByte('Z'); this.data = new Data(this.blockSize100k); this.blockSorter = new BlockSort(this.data); // huffmanised magic bytes bsPutUByte('h'); bsPutUByte('0' + this.blockSize100k); this.combinedCRC = 0; initBlock(); }
void blockSort(final BZip2CompressorOutputStream.Data data, final int last) { this.workLimit = WORK_FACTOR * last; this.workDone = 0; this.firstAttempt = true; if (last + 1 < 10000) { fallbackSort(data, last); } else { mainSort(data, last); if (this.firstAttempt && (this.workDone > this.workLimit)) { fallbackSort(data, last); } } final int[] fmap = data.fmap; data.origPtr = -1; for (int i = 0; i <= last; i++) { if (fmap[i] == 0) { data.origPtr = i; break; } } // assert (data.origPtr != -1) : data.origPtr; }
/** * swaps two intervals starting at yyp1 and yyp2 of length yyn inside fmap. */ private void fvswap(int[] fmap, int yyp1, int yyp2, int yyn) { while (yyn > 0) { fswap(fmap, yyp1, yyp2); yyp1++; yyp2++; yyn--; } }
private void blockSort() { blockSorter.blockSort(data, last); }