244 Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
245 Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
246 Int32 nGroups, nBytes;
265 VPrintf3(
" %d in block, %d after MTF & 1-2 coding, "
266 "%d+2 syms in use\n",
271 for (v = 0; v < alphaSize; v++)
276 if (s->
nMTF < 200) nGroups = 2;
else
277 if (s->
nMTF < 600) nGroups = 3;
else
278 if (s->
nMTF < 1200) nGroups = 4;
else
279 if (s->
nMTF < 2400) nGroups = 5;
else
284 Int32 nPart, remF, tFreq, aFreq;
290 tFreq = remF / nPart;
293 while (aFreq < tFreq && ge < alphaSize-1) {
299 && nPart != nGroups && nPart != 1
300 && ((nGroups-nPart) % 2 == 1)) {
306 VPrintf5(
" initial group %d, [%d .. %d], "
307 "has %d syms (%4.1f%%)\n",
308 nPart, gs, ge, aFreq,
309 (100.0 * (
float)aFreq) / (
float)(s->
nMTF) );
311 for (v = 0; v < alphaSize; v++)
312 if (v >= gs && v <= ge)
327 for (t = 0; t < nGroups; t++) fave[t] = 0;
329 for (t = 0; t < nGroups; t++)
330 for (v = 0; v < alphaSize; v++)
338 for (v = 0; v < alphaSize; v++) {
351 if (gs >= s->
nMTF)
break;
359 for (t = 0; t < nGroups; t++) cost[t] = 0;
361 if (nGroups == 6 && 50 == ge-gs+1) {
363 register UInt32 cost01, cost23, cost45;
365 cost01 = cost23 = cost45 = 0;
367 # define BZ_ITER(nn) \
368 icv = mtfv[gs+(nn)]; \
369 cost01 += s->len_pack[icv][0]; \
370 cost23 += s->len_pack[icv][1]; \
371 cost45 += s->len_pack[icv][2]; \
386 cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
387 cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
388 cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
392 for (i = gs; i <= ge; i++) {
394 for (t = 0; t < nGroups; t++) cost[t] += s->
len[t][icv];
402 bc = 999999999; bt = -1;
403 for (t = 0; t < nGroups; t++)
404 if (cost[t] < bc) { bc = cost[t]; bt = t; };
413 if (nGroups == 6 && 50 == ge-gs+1) {
416 # define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++
433 for (i = gs; i <= ge; i++)
434 s->
rfreq[bt][ mtfv[i] ]++;
440 VPrintf2 (
" pass %d: size is %d, grp uses are ",
442 for (t = 0; t < nGroups; t++)
452 for (t = 0; t < nGroups; t++)
460 nSelectors <= (2 + (900000 / BZ_G_SIZE)),
467 for (i = 0; i < nGroups; i++) pos[i] = i;
468 for (i = 0; i < nSelectors; i++) {
472 while ( ll_i != tmp ) {
484 for (t = 0; t < nGroups; t++) {
487 for (i = 0; i < alphaSize; i++) {
488 if (s->
len[t][i] > maxLen) maxLen = s->
len[t][i];
489 if (s->
len[t][i] < minLen) minLen = s->
len[t][i];
491 AssertH ( !(maxLen > 17 ), 3004 );
492 AssertH ( !(minLen < 1), 3005 );
494 minLen, maxLen, alphaSize );
500 for (i = 0; i < 16; i++) {
502 for (j = 0; j < 16; j++)
503 if (s->
inUse[i * 16 + j]) inUse16[i] =
True;
507 for (i = 0; i < 16; i++)
508 if (inUse16[i])
bsW(s,1,1);
else bsW(s,1,0);
510 for (i = 0; i < 16; i++)
512 for (j = 0; j < 16; j++) {
513 if (s->
inUse[i * 16 + j])
bsW(s,1,1);
else bsW(s,1,0);
522 bsW ( s, 3, nGroups );
523 bsW ( s, 15, nSelectors );
524 for (i = 0; i < nSelectors; i++) {
534 for (t = 0; t < nGroups; t++) {
537 for (i = 0; i < alphaSize; i++) {
538 while (curr < s->len[t][i]) {
bsW(s,2,2); curr++; };
539 while (curr > s->
len[t][i]) {
bsW(s,2,3); curr--; };
552 if (gs >= s->
nMTF)
break;
553 ge = gs + BZ_G_SIZE - 1;
557 if (nGroups == 6 && 50 == ge-gs+1) {
560 UChar* s_len_sel_selCtr
562 Int32* s_code_sel_selCtr
565 # define BZ_ITAH(nn) \
566 mtfv_i = mtfv[gs+(nn)]; \
568 s_len_sel_selCtr[mtfv_i], \
569 s_code_sel_selCtr[mtfv_i] )
586 for (i = gs; i <= ge; i++) {
597 AssertH( selCtr == nSelectors, 3007 );
#define VPrintf1(zf, za1)
void BZ2_hbMakeCodeLengths(UChar *, Int32 *, Int32, Int32)
#define VPrintf2(zf, za1, za2)
UChar selectorMtf[BZ_MAX_SELECTORS]
#define AssertH(cond, errcode)
Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]
UChar selector[BZ_MAX_SELECTORS]
UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]
#define VPrintf3(zf, za1, za2, za3)
Int32 mtfFreq[BZ_MAX_ALPHA_SIZE]
void BZ2_hbAssignCodes(Int32 *, UChar *, Int32, Int32, Int32)
Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]
static __inline__ void bsW(EState *s, Int32 n, UInt32 v)
UChar len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]
#define VPrintf5(zf, za1, za2, za3, za4, za5)