MCPcopy Create free account
hub / github.com/CobaltFusion/DebugViewPP / ComputeTable

Function ComputeTable

Libraries/snappy/snappy.cc:568–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

566}
567
568static void ComputeTable() {
569 uint16 dst[256];
570
571 // Place invalid entries in all places to detect missing initialization
572 int assigned = 0;
573 for (int i = 0; i < 256; i++) {
574 dst[i] = 0xffff;
575 }
576
577 // Small LITERAL entries. We store (len-1) in the top 6 bits.
578 for (unsigned int len = 1; len <= 60; len++) {
579 dst[LITERAL | ((len-1) << 2)] = MakeEntry(0, len, 0);
580 assigned++;
581 }
582
583 // Large LITERAL entries. We use 60..63 in the high 6 bits to
584 // encode the number of bytes of length info that follow the opcode.
585 for (unsigned int extra_bytes = 1; extra_bytes <= 4; extra_bytes++) {
586 // We set the length field in the lookup table to 1 because extra
587 // bytes encode len-1.
588 dst[LITERAL | ((extra_bytes+59) << 2)] = MakeEntry(extra_bytes, 1, 0);
589 assigned++;
590 }
591
592 // COPY_1_BYTE_OFFSET.
593 //
594 // The tag byte in the compressed data stores len-4 in 3 bits, and
595 // offset/256 in 5 bits. offset%256 is stored in the next byte.
596 //
597 // This format is used for length in range [4..11] and offset in
598 // range [0..2047]
599 for (unsigned int len = 4; len < 12; len++) {
600 for (unsigned int offset = 0; offset < 2048; offset += 256) {
601 dst[COPY_1_BYTE_OFFSET | ((len-4)<<2) | ((offset>>8)<<5)] =
602 MakeEntry(1, len, offset>>8);
603 assigned++;
604 }
605 }
606
607 // COPY_2_BYTE_OFFSET.
608 // Tag contains len-1 in top 6 bits, and offset in next two bytes.
609 for (unsigned int len = 1; len <= 64; len++) {
610 dst[COPY_2_BYTE_OFFSET | ((len-1)<<2)] = MakeEntry(2, len, 0);
611 assigned++;
612 }
613
614 // COPY_4_BYTE_OFFSET.
615 // Tag contents len-1 in top 6 bits, and offset in next four bytes.
616 for (unsigned int len = 1; len <= 64; len++) {
617 dst[COPY_4_BYTE_OFFSET | ((len-1)<<2)] = MakeEntry(4, len, 0);
618 assigned++;
619 }
620
621 // Check that each entry was initialized exactly once.
622 if (assigned != 256) {
623 fprintf(stderr, "ComputeTable: assigned only %d of 256\n", assigned);
624 abort();
625 }

Callers

nothing calls this directly

Calls 1

MakeEntryFunction · 0.85

Tested by

no test coverage detected