Lines Matching defs:tree

13  *      Each code tree is stored in a compressed form which is itself
91 /* The static literal tree. Since the bit lengths are imposed, there is no
93 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
98 /* The static distance tree. (Actually a trivial tree since all codes use
122 const ct_data *static_tree; /* static tree or NULL */
125 int elems; /* max number of elements in the tree */
144 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
146 local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
148 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
149 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
167 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
168 /* Send a code of the given tree. c and tree must not have side effects */
171 # define send_code(s, c, tree) \
173 send_bits(s, tree[c].Code, tree[c].Len); }
243 int n; /* iterates over tree elements */
249 /* number of codes at each bit length for an optimal tree */
293 /* Construct the codes of the static literal tree */
301 * tree construction to get a canonical Huffman tree (longest code
306 /* The static distance tree is trivial: */
381 * Initialize the tree data structures for a new zlib stream.
415 int n; /* iterates over tree elements */
428 /* Index within the heap array of least frequent node in the Huffman tree */
435 #define pqremove(s, tree, top) \
439 pqdownheap(s, tree, SMALLEST); \
443 * Compares to subtrees, using the tree depth as tie breaker when
446 #define smaller(tree, n, m, depth) \
447 (tree[n].Freq < tree[m].Freq || \
448 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
451 * Restore the heap property by moving down the tree starting at node k,
456 local void pqdownheap(s, tree, k)
458 ct_data *tree; /* the tree to restore */
466 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
470 if (smaller(tree, v, s->heap[j], s->depth)) break;
475 /* And continue down the tree, setting j to the left son of k */
482 * Compute the optimal bit lengths for a tree and update the total bit length
485 * above are the tree nodes sorted by increasing frequency.
493 tree_desc *desc; /* the tree descriptor */
495 ct_data *tree = desc->dyn_tree;
502 int n, m; /* iterate over the tree elements */
511 * overflow in the case of the bit length tree).
513 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
517 bits = tree[tree[n].Dad].Len + 1;
519 tree[n].Len = (ush)bits;
520 /* We overwrite tree[n].Dad which is no longer needed */
527 f = tree[n].Freq;
540 s->bl_count[bits]--; /* move one leaf down the tree */
559 if (tree[m].Len != (unsigned) bits) {
560 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
561 s->opt_len += ((long)bits - (long)tree[m].Len)
562 *(long)tree[m].Freq;
563 tree[m].Len = (ush)bits;
571 * Generate the codes for a given tree and bit counts (which need not be
574 * the given tree and the field len is set for all tree elements.
575 * OUT assertion: the field code is set for all tree elements of non
578 local void gen_codes (tree, max_code, bl_count)
579 ct_data *tree; /* the tree to decorate */
602 int len = tree[n].Len;
605 tree[n].Code = bi_reverse(next_code[len]++, len);
607 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
608 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
613 * Construct one Huffman tree and assigns the code bit strings and lengths.
615 * IN assertion: the field freq is set for all tree elements.
622 tree_desc *desc; /* the tree descriptor */
624 ct_data *tree = desc->dyn_tree;
638 if (tree[n].Freq != 0) {
642 tree[n].Len = 0;
653 tree[node].Freq = 1;
660 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
663 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
665 /* Construct the Huffman tree by repeatedly combining the least two
668 node = elems; /* next internal node of the tree */
670 pqremove(s, tree, n); /* n = node of least frequency */
677 tree[node].Freq = tree[n].Freq + tree[m].Freq;
679 tree[n].Dad = tree[m].Dad = (ush)node;
681 if (tree == s->bl_tree) {
683 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
688 pqdownheap(s, tree, SMALLEST);
700 gen_codes ((ct_data *)tree, max_code, s->bl_count);
704 * Scan a literal or distance tree to determine the frequencies of the codes
705 * in the bit length tree.
707 local void scan_tree (s, tree, max_code)
709 ct_data *tree; /* the tree to be scanned */
712 int n; /* iterates over all tree elements */
715 int nextlen = tree[0].Len; /* length of next code */
721 tree[max_code+1].Len = (ush)0xffff; /* guard */
724 curlen = nextlen; nextlen = tree[n+1].Len;
749 * Send a literal or distance tree in compressed form, using the codes in
752 local void send_tree (s, tree, max_code)
754 ct_data *tree; /* the tree to be scanned */
757 int n; /* iterates over all tree elements */
760 int nextlen = tree[0].Len; /* length of next code */
765 /* tree[max_code+1].Len = -1; */ /* guard already set */
769 curlen = nextlen; nextlen = tree[n+1].Len;
800 * Construct the Huffman tree for the bit lengths and return the index in
812 /* Build the bit length tree: */
814 /* opt_len now includes the length of the tree representations, except
825 /* Update opt_len to include the bit length tree and counts */
835 * lengths of the bit length codes, the literal tree and the distance tree.
840 int lcodes, dcodes, blcodes; /* number of codes for each tree */
855 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
857 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
858 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
860 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
861 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
945 * the compressed block data, excluding the tree representations.
948 /* Build the bit length tree for the above two trees, and get the index
1073 ct_data *ltree; /* literal tree */
1074 ct_data *dtree; /* distance tree */