MCPcopy Create free account
hub / github.com/SheepChef/Abracadabra / append_final_bits

Function append_final_bits

src/javascript/unishox2.js:491–542  ·  view source on GitHub ↗
(
  out,
  olen,
  ol,
  state,
  is_all_upper,
  usx_hcodes,
  usx_hcode_lens
)

Source from the content-addressed store, hash-verified

489
490/// Appends the terminator code depending on the state, preset and whether full terminator needs to be encoded to out or not \n
491function append_final_bits(
492 out,
493 olen,
494 ol,
495 state,
496 is_all_upper,
497 usx_hcodes,
498 usx_hcode_lens
499) {
500 if (usx_hcode_lens[USX_ALPHA]) {
501 if (USX_NUM != state) {
502 // for num state, append TERM_CODE directly
503 // for other state, switch to Num Set first
504 ol = append_switch_code(out, olen, ol, state);
505 ol = append_bits(
506 out,
507 olen,
508 ol,
509 usx_hcodes[USX_NUM],
510 usx_hcode_lens[USX_NUM]
511 );
512 }
513 ol = append_bits(
514 out,
515 olen,
516 ol,
517 usx_vcodes[TERM_CODE & 0x1f],
518 usx_vcode_lens[TERM_CODE & 0x1f]
519 );
520 } else {
521 // preset 1, terminate at 2 or 3 SW_CODE, i.e., 4 or 6 continuous 0 bits
522 // see discussion: https://github.com/siara-cc/Unishox/issues/19#issuecomment-922435580
523 ol = append_bits(
524 out,
525 olen,
526 ol,
527 TERM_BYTE_PRESET_1,
528 is_all_upper ? TERM_BYTE_PRESET_1_LEN_UPPER : TERM_BYTE_PRESET_1_LEN_LOWER
529 );
530 }
531
532 // fill byte with the last bit
533 ol = append_bits(
534 out,
535 olen,
536 ol,
537 ol == 0 || out[(ol - 1) / 8] << ((ol - 1) & 7) >= 0 ? 0 : 0xff,
538 (8 - (ol % 8)) & 7
539 );
540
541 return ol;
542}
543
544function compare_arr(arr1, arr2, is_str) {
545 if (is_str) return arr1 === arr2;

Callers 1

unishox2_compressFunction · 0.85

Calls 2

append_switch_codeFunction · 0.85
append_bitsFunction · 0.85

Tested by

no test coverage detected