MCPcopy Create free account
hub / github.com/F-Stack/f-stack / scan_tree

Function scan_tree

freebsd/contrib/zlib/trees.c:703–742  ·  view source on GitHub ↗

=========================================================================== * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */

(s, tree, max_code)

Source from the content-addressed store, hash-verified

701 * in the bit length tree.
702 */
703local void scan_tree (s, tree, max_code)
704 deflate_state *s;
705 ct_data *tree; /* the tree to be scanned */
706 int max_code; /* and its largest code of non zero frequency */
707{
708 int n; /* iterates over all tree elements */
709 int prevlen = -1; /* last emitted length */
710 int curlen; /* length of current code */
711 int nextlen = tree[0].Len; /* length of next code */
712 int count = 0; /* repeat count of the current code */
713 int max_count = 7; /* max repeat count */
714 int min_count = 4; /* min repeat count */
715
716 if (nextlen == 0) max_count = 138, min_count = 3;
717 tree[max_code+1].Len = (ush)0xffff; /* guard */
718
719 for (n = 0; n <= max_code; n++) {
720 curlen = nextlen; nextlen = tree[n+1].Len;
721 if (++count < max_count && curlen == nextlen) {
722 continue;
723 } else if (count < min_count) {
724 s->bl_tree[curlen].Freq += count;
725 } else if (curlen != 0) {
726 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
727 s->bl_tree[REP_3_6].Freq++;
728 } else if (count <= 10) {
729 s->bl_tree[REPZ_3_10].Freq++;
730 } else {
731 s->bl_tree[REPZ_11_138].Freq++;
732 }
733 count = 0; prevlen = curlen;
734 if (nextlen == 0) {
735 max_count = 138, min_count = 3;
736 } else if (curlen == nextlen) {
737 max_count = 6, min_count = 3;
738 } else {
739 max_count = 7, min_count = 4;
740 }
741 }
742}
743
744/* ===========================================================================
745 * Send a literal or distance tree in compressed form, using the codes in

Callers 1

build_bl_treeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected