@@ -113,7 +113,7 @@ public static void decompress(BZipContext bzip2Context) {
113
113
else
114
114
curr --;
115
115
} while (true );
116
- bzip2Context .aByteArrayArray822 [t ][i ] = (byte ) curr ;
116
+ bzip2Context .codeLengths [t ][i ] = (byte ) curr ;
117
117
}
118
118
119
119
}
@@ -122,14 +122,14 @@ public static void decompress(BZipContext bzip2Context) {
122
122
byte minLen = 32 ;
123
123
int maxLen = 0 ;
124
124
for (int i = 0 ; i < alphaSize ; i ++) {
125
- if (bzip2Context .aByteArrayArray822 [t ][i ] > maxLen )
126
- maxLen = bzip2Context .aByteArrayArray822 [t ][i ];
127
- if (bzip2Context .aByteArrayArray822 [t ][i ] < minLen )
128
- minLen = bzip2Context .aByteArrayArray822 [t ][i ];
125
+ if (bzip2Context .codeLengths [t ][i ] > maxLen )
126
+ maxLen = bzip2Context .codeLengths [t ][i ];
127
+ if (bzip2Context .codeLengths [t ][i ] < minLen )
128
+ minLen = bzip2Context .codeLengths [t ][i ];
129
129
}
130
130
131
- method294 (bzip2Context .limit [t ], bzip2Context .base [t ], bzip2Context .perm [t ],
132
- bzip2Context .aByteArrayArray822 [t ], minLen , maxLen , alphaSize );
131
+ createHuffmanDecodingTables (bzip2Context .limit [t ], bzip2Context .base [t ], bzip2Context .perm [t ],
132
+ bzip2Context .codeLengths [t ], minLen , maxLen , alphaSize );
133
133
bzip2Context .minLens [t ] = minLen ;
134
134
}
135
135
@@ -445,31 +445,42 @@ public static byte getBit(BZipContext context) {
445
445
return (byte ) getBits (1 , context );
446
446
}
447
447
448
- public static void method294 (int [] arg0 , int [] arg1 , int [] arg2 , byte [] arg3 , int arg4 , int arg5 , int arg6 ) {
448
+ private static void createHuffmanDecodingTables (int [] limit , int [] base , int [] perm , byte [] codeLengths , int minLen , int maxLen , int alphabetSize ) {
449
449
int i = 0 ;
450
- for (int i_84_ = arg4 ; i_84_ <= arg5 ; i_84_ ++) {
451
- for (int i_85_ = 0 ; i_85_ < arg6 ; i_85_ ++) {
452
- if (arg3 [i_85_ ] == i_84_ ) {
453
- arg2 [i ] = i_85_ ;
450
+
451
+ // Populate the mapping from canonical code index to output symbol
452
+ for (int len = minLen ; len <= maxLen ; len ++) {
453
+ for (int symIndex = 0 ; symIndex < alphabetSize ; symIndex ++) {
454
+ if (codeLengths [symIndex ] == len ) {
455
+ perm [i ] = symIndex ;
454
456
i ++;
455
457
}
456
458
}
457
459
}
458
- for (int i_86_ = 0 ; i_86_ < 23 ; i_86_ ++)
459
- arg1 [i_86_ ] = 0 ;
460
- for (int i_87_ = 0 ; i_87_ < arg6 ; i_87_ ++)
461
- arg1 [arg3 [i_87_ ] + 1 ]++;
462
- for (int i_88_ = 1 ; i_88_ < 23 ; i_88_ ++)
463
- arg1 [i_88_ ] += arg1 [i_88_ - 1 ];
464
- for (int i_89_ = 0 ; i_89_ < 23 ; i_89_ ++)
465
- arg0 [i_89_ ] = 0 ;
466
- int i_90_ = 0 ;
467
- for (int i_91_ = arg4 ; i_91_ <= arg5 ; i_91_ ++) {
468
- i_90_ += arg1 [i_91_ + 1 ] - arg1 [i_91_ ];
469
- arg0 [i_91_ ] = i_90_ - 1 ;
470
- i_90_ <<= 1 ;
460
+
461
+ // reset base arrays
462
+ for (int index = 0 ; index < 23 ; index ++)
463
+ base [index ] = 0 ;
464
+ for (int index = 0 ; index < alphabetSize ; index ++)
465
+ base [codeLengths [index ] + 1 ]++;
466
+ for (int index = 1 ; index < 23 ; index ++)
467
+ base [index ] += base [index - 1 ];
468
+
469
+ // reset limit array
470
+ for (int index = 0 ; index < 23 ; index ++)
471
+ limit [index ] = 0 ;
472
+
473
+ // Calculate the first and last Huffman code for each code length (codes at a given
474
+ // length are sequential in value)
475
+ int code = 0 ;
476
+ for (int len = minLen ; len <= maxLen ; len ++) {
477
+ code += base [len + 1 ] - base [len ];
478
+ limit [len ] = code - 1 ;
479
+ code <<= 1 ;
471
480
}
472
- for (int i_92_ = arg4 + 1 ; i_92_ <= arg5 ; i_92_ ++)
473
- arg1 [i_92_ ] = (arg0 [i_92_ - 1 ] + 1 << 1 ) - arg1 [i_92_ ];
481
+
482
+ // Update base array with appropriate values for decoding
483
+ for (int len = minLen + 1 ; len <= maxLen ; len ++)
484
+ base [len ] = (limit [len - 1 ] + 1 << 1 ) - base [len ];
474
485
}
475
486
}
0 commit comments