MCPcopy
hub / github.com/google/brotli / readComplexHuffmanCode

Method readComplexHuffmanCode

java/org/brotli/dec/Decode.java:609–643  ·  view source on GitHub ↗
(int alphabetSizeLimit, int skip,
      int[] tableGroup, int tableIdx, State s)

Source from the content-addressed store, hash-verified

607
608 // Decode Huffman-coded code lengths.
609 private static int readComplexHuffmanCode(int alphabetSizeLimit, int skip,
610 int[] tableGroup, int tableIdx, State s) {
611 // TODO(eustas): Avoid allocation?
612 final int[] codeLengths = new int[alphabetSizeLimit];
613 final int[] codeLengthCodeLengths = new int[CODE_LENGTH_CODES];
614 int space = 32;
615 int numCodes = 0;
616 for (int i = skip; i < CODE_LENGTH_CODES; ++i) {
617 final int codeLenIdx = CODE_LENGTH_CODE_ORDER[i];
618 BitReader.fillBitWindow(s);
619 final int p = BitReader.peekBits(s) & 15;
620 // TODO(eustas): Demultiplex FIXED_TABLE.
621 s.bitOffset += FIXED_TABLE[p] >> 16;
622 final int v = FIXED_TABLE[p] & 0xFFFF;
623 codeLengthCodeLengths[codeLenIdx] = v;
624 if (v != 0) {
625 space -= (32 >> v);
626 numCodes++;
627 if (space <= 0) {
628 break;
629 }
630 }
631 }
632 if (space != 0 && numCodes != 1) {
633 return Utils.makeError(s, BROTLI_ERROR_CORRUPTED_HUFFMAN_CODE_HISTOGRAM);
634 }
635
636 final int result = readHuffmanCodeLengths(codeLengthCodeLengths, alphabetSizeLimit, codeLengths, s);
637 if (result < BROTLI_OK) {
638 return result;
639 }
640
641 return Huffman.buildHuffmanTable(
642 tableGroup, tableIdx, HUFFMAN_TABLE_BITS, codeLengths, alphabetSizeLimit);
643 }
644
645 /**
646 * Decodes Huffman table from bit-stream.

Callers 1

readHuffmanCodeMethod · 0.95

Calls 5

fillBitWindowMethod · 0.95
peekBitsMethod · 0.95
makeErrorMethod · 0.95
buildHuffmanTableMethod · 0.95

Tested by

no test coverage detected