* Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. * @param blTree
(blTree: Tree)
| 309 | * @param blTree |
| 310 | */ |
| 311 | public calcBLFreq(blTree: Tree) { |
| 312 | let maxCount: number; /* max repeat count */ |
| 313 | let minCount: number; /* min repeat count */ |
| 314 | let count: number; /* repeat count of the current code */ |
| 315 | let curlen = -1; /* length of current code */ |
| 316 | |
| 317 | let i = 0; |
| 318 | while (i < this.numCodes) { |
| 319 | count = 1; |
| 320 | const nextlen = this.length![i]; |
| 321 | if (nextlen === 0) { |
| 322 | maxCount = 138; |
| 323 | minCount = 3; |
| 324 | } else { |
| 325 | maxCount = 6; |
| 326 | minCount = 3; |
| 327 | if (curlen !== nextlen) { |
| 328 | blTree.freqs[nextlen]++; |
| 329 | count = 0; |
| 330 | } |
| 331 | } |
| 332 | curlen = nextlen; |
| 333 | i++; |
| 334 | |
| 335 | while (i < this.numCodes && curlen === this.length![i]) { |
| 336 | i++; |
| 337 | if (++count >= maxCount) { |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (count < minCount) { |
| 343 | blTree.freqs[curlen] += count; |
| 344 | } else if (curlen !== 0) { |
| 345 | blTree.freqs[Tree._repeat3To6]++; |
| 346 | } else if (count <= 10) { |
| 347 | blTree.freqs[Tree._repeat3To10]++; |
| 348 | } else { |
| 349 | blTree.freqs[Tree._repeat11To138]++; |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Set static codes and length |