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

Function readSimpleHuffmanCode

js/decode.ts:368–421  ·  view source on GitHub ↗
(alphabetSizeMax: number, alphabetSizeLimit: number, tableGroup: Int32Array, tableIdx: number, s: State)

Source from the content-addressed store, hash-verified

366 return 0;
367}
368function readSimpleHuffmanCode(alphabetSizeMax: number, alphabetSizeLimit: number, tableGroup: Int32Array, tableIdx: number, s: State): number {
369 const codeLengths = new Int32Array(alphabetSizeLimit);
370 const symbols = new Int32Array(4);
371 const maxBits: number = 1 + log2floor(alphabetSizeMax - 1);
372 const numSymbols: number = readFewBits(s, 2) + 1;
373 for (let i = 0; i < numSymbols; ++i) {
374 if (s.bitOffset >= 16) {
375 s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
376 s.bitOffset -= 16;
377 }
378 const symbol: number = readFewBits(s, maxBits);
379 if (symbol >= alphabetSizeLimit) {
380 return makeError(s, -15);
381 }
382 symbols[i] = symbol;
383 }
384 const result: number = checkDupes(s, symbols, numSymbols);
385 if (result < 0) {
386 return result;
387 }
388 let histogramId: number = numSymbols;
389 if (numSymbols === 4) {
390 histogramId += readFewBits(s, 1);
391 }
392 switch(histogramId) {
393 case 1:
394 codeLengths[symbols[0]] = 1;
395 break;
396 case 2:
397 codeLengths[symbols[0]] = 1;
398 codeLengths[symbols[1]] = 1;
399 break;
400 case 3:
401 codeLengths[symbols[0]] = 1;
402 codeLengths[symbols[1]] = 2;
403 codeLengths[symbols[2]] = 2;
404 break;
405 case 4:
406 codeLengths[symbols[0]] = 2;
407 codeLengths[symbols[1]] = 2;
408 codeLengths[symbols[2]] = 2;
409 codeLengths[symbols[3]] = 2;
410 break;
411 case 5:
412 codeLengths[symbols[0]] = 1;
413 codeLengths[symbols[1]] = 2;
414 codeLengths[symbols[2]] = 3;
415 codeLengths[symbols[3]] = 3;
416 break;
417 default:
418 break;
419 }
420 return buildHuffmanTable(tableGroup, tableIdx, 8, codeLengths, alphabetSizeLimit);
421}
422function readComplexHuffmanCode(alphabetSizeLimit: number, skip: number, tableGroup: Int32Array, tableIdx: number, s: State): number {
423 const codeLengths = new Int32Array(alphabetSizeLimit);
424 const codeLengthCodeLengths = new Int32Array(18);

Callers 1

readHuffmanCodeFunction · 0.70

Calls 5

log2floorFunction · 0.70
readFewBitsFunction · 0.70
makeErrorFunction · 0.70
checkDupesFunction · 0.70
buildHuffmanTableFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…