Lines Matching defs:tree
12 * 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); }
242 int n; /* iterates over tree elements */
248 /* number of codes at each bit length for an optimal tree */
292 /* Construct the codes of the static literal tree */
300 * tree construction to get a canonical Huffman tree (longest code
305 /* The static distance tree is trivial: */
380 * Initialize the tree data structures for a new zlib stream.
414 int n; /* iterates over tree elements */
427 /* Index within the heap array of least frequent node in the Huffman tree */
434 #define pqremove(s, tree, top) \
438 pqdownheap(s, tree, SMALLEST); \
442 * Compares to subtrees, using the tree depth as tie breaker when
445 #define smaller(tree, n, m, depth) \
446 (tree[n].Freq < tree[m].Freq || \
447 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
450 * Restore the heap property by moving down the tree starting at node k,
455 local void pqdownheap(s, tree, k)
457 ct_data *tree; /* the tree to restore */
465 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
469 if (smaller(tree, v, s->heap[j], s->depth)) break;
474 /* And continue down the tree, setting j to the left son of k */
481 * Compute the optimal bit lengths for a tree and update the total bit length
484 * above are the tree nodes sorted by increasing frequency.
492 tree_desc *desc; /* the tree descriptor */
494 ct_data *tree = desc->dyn_tree;
501 int n, m; /* iterate over the tree elements */
510 * overflow in the case of the bit length tree).
512 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
516 bits = tree[tree[n].Dad].Len + 1;
518 tree[n].Len = (ush)bits;
519 /* We overwrite tree[n].Dad which is no longer needed */
526 f = tree[n].Freq;
539 s->bl_count[bits]--; /* move one leaf down the tree */
558 if ((unsigned) tree[m].Len != (unsigned) bits) {
559 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
560 s->opt_len += ((long)bits - (long)tree[m].Len)
561 *(long)tree[m].Freq;
562 tree[m].Len = (ush)bits;
570 * Generate the codes for a given tree and bit counts (which need not be
573 * the given tree and the field len is set for all tree elements.
574 * OUT assertion: the field code is set for all tree elements of non
577 local void gen_codes (tree, max_code, bl_count)
578 ct_data *tree; /* the tree to decorate */
601 int len = tree[n].Len;
604 tree[n].Code = bi_reverse(next_code[len]++, len);
606 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
607 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
612 * Construct one Huffman tree and assigns the code bit strings and lengths.
614 * IN assertion: the field freq is set for all tree elements.
621 tree_desc *desc; /* the tree descriptor */
623 ct_data *tree = desc->dyn_tree;
637 if (tree[n].Freq != 0) {
641 tree[n].Len = 0;
652 tree[node].Freq = 1;
659 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
662 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
664 /* Construct the Huffman tree by repeatedly combining the least two
667 node = elems; /* next internal node of the tree */
669 pqremove(s, tree, n); /* n = node of least frequency */
676 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));
946 * the compressed block data, excluding the tree representations.
949 /* Build the bit length tree for the above two trees, and get the index
1074 ct_data *ltree; /* literal tree */
1075 ct_data *dtree; /* distance tree */