(t: Huffman)
| 79 | } |
| 80 | |
| 81 | private static _treeCompress(t: Huffman): Huffman { |
| 82 | const d: number = HuffTools._treeDepth(t); |
| 83 | if (d === 0) { |
| 84 | return t; |
| 85 | } |
| 86 | if (d === 1) { |
| 87 | if (t instanceof NeedBit) { |
| 88 | return new NeedBit(HuffTools._treeCompress(t.left), HuffTools._treeCompress(t.right)); |
| 89 | } |
| 90 | throw new FormatError('assert'); |
| 91 | } |
| 92 | const size: number = 1 << d; |
| 93 | const table: Huffman[] = []; |
| 94 | for (let i: number = 0; i < size; i++) { |
| 95 | table.push(new Found(-1)); |
| 96 | } |
| 97 | HuffTools._treeWalk(table, 0, 0, d, t); |
| 98 | return new NeedBits(d, table); |
| 99 | } |
| 100 | |
| 101 | private static _treeWalk(table: Huffman[], p: number, cd: number, d: number, t: Huffman): void { |
| 102 | if (t instanceof NeedBit) { |
no test coverage detected