Lines Matching defs:tree
13 * Each code tree is stored in a compressed form which is itself
92 /* The static literal tree. Since the bit lengths are imposed, there is no
94 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
99 /* The static distance tree. (Actually a trivial tree since all codes use
123 const ct_data *static_tree; /* static tree or NULL */
126 int elems; /* max number of elements in the tree */
145 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
147 local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
149 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
150 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
168 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
169 /* Send a code of the given tree. c and tree must not have side effects */
172 # define send_code(s, c, tree) \
174 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 */
295 /* Construct the codes of the static literal tree */
303 * tree construction to get a canonical Huffman tree (longest code
308 /* The static distance tree is trivial: */
384 * Initialize the tree data structures for a new zlib stream.
418 int n; /* iterates over tree elements */
431 /* Index within the heap array of least frequent node in the Huffman tree */
438 #define pqremove(s, tree, top) \
442 pqdownheap(s, tree, SMALLEST); \
446 * Compares to subtrees, using the tree depth as tie breaker when
449 #define smaller(tree, n, m, depth) \
450 (tree[n].Freq < tree[m].Freq || \
451 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
454 * Restore the heap property by moving down the tree starting at node k,
459 local void pqdownheap(s, tree, k)
461 ct_data *tree; /* the tree to restore */
469 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
473 if (smaller(tree, v, s->heap[j], s->depth)) break;
478 /* And continue down the tree, setting j to the left son of k */
485 * Compute the optimal bit lengths for a tree and update the total bit length
488 * above are the tree nodes sorted by increasing frequency.
496 tree_desc *desc; /* the tree descriptor */
498 ct_data *tree = desc->dyn_tree;
505 int n, m; /* iterate over the tree elements */
514 * overflow in the case of the bit length tree).
516 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
520 bits = tree[tree[n].Dad].Len + 1;
522 tree[n].Len = (ush)bits;
523 /* We overwrite tree[n].Dad which is no longer needed */
530 f = tree[n].Freq;
543 s->bl_count[bits]--; /* move one leaf down the tree */
562 if ((unsigned) tree[m].Len != (unsigned) bits) {
563 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
564 s->opt_len += ((long)bits - (long)tree[m].Len)
565 *(long)tree[m].Freq;
566 tree[m].Len = (ush)bits;
574 * Generate the codes for a given tree and bit counts (which need not be
577 * the given tree and the field len is set for all tree elements.
578 * OUT assertion: the field code is set for all tree elements of non
581 local void gen_codes (tree, max_code, bl_count)
582 ct_data *tree; /* the tree to decorate */
605 int len = tree[n].Len;
608 tree[n].Code = bi_reverse(next_code[len]++, len);
610 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
611 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
616 * Construct one Huffman tree and assigns the code bit strings and lengths.
618 * IN assertion: the field freq is set for all tree elements.
625 tree_desc *desc; /* the tree descriptor */
627 ct_data *tree = desc->dyn_tree;
641 if (tree[n].Freq != 0) {
645 tree[n].Len = 0;
656 tree[node].Freq = 1;
663 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
666 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
668 /* Construct the Huffman tree by repeatedly combining the least two
671 node = elems; /* next internal node of the tree */
673 pqremove(s, tree, n); /* n = node of least frequency */
680 tree[node].Freq = tree[n].Freq + tree[m].Freq;
683 tree[n].Dad = tree[m].Dad = (ush)node;
685 if (tree == s->bl_tree) {
687 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
692 pqdownheap(s, tree, SMALLEST);
704 gen_codes ((ct_data *)tree, max_code, s->bl_count);
708 * Scan a literal or distance tree to determine the frequencies of the codes
709 * in the bit length tree.
711 local void scan_tree (s, tree, max_code)
713 ct_data *tree; /* the tree to be scanned */
716 int n; /* iterates over all tree elements */
719 int nextlen = tree[0].Len; /* length of next code */
725 tree[max_code+1].Len = (ush)0xffff; /* guard */
728 curlen = nextlen; nextlen = tree[n+1].Len;
753 * Send a literal or distance tree in compressed form, using the codes in
756 local void send_tree (s, tree, max_code)
758 ct_data *tree; /* the tree to be scanned */
761 int n; /* iterates over all tree elements */
764 int nextlen = tree[0].Len; /* length of next code */
769 /* tree[max_code+1].Len = -1; */ /* guard already set */
773 curlen = nextlen; nextlen = tree[n+1].Len;
804 * Construct the Huffman tree for the bit lengths and return the index in
816 /* Build the bit length tree: */
818 /* opt_len now includes the length of the tree representations, except
829 /* Update opt_len to include the bit length tree and counts */
839 * lengths of the bit length codes, the literal tree and the distance tree.
844 int lcodes, dcodes, blcodes; /* number of codes for each tree */
859 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
861 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
862 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
864 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
865 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
950 * the compressed block data, excluding the tree representations.
953 /* Build the bit length tree for the above two trees, and get the index
1056 ct_data *ltree; /* literal tree */
1057 ct_data *dtree; /* distance tree */