Lines Matching refs:tree

13  *	Each code tree is stored in a compressed form which is itself
93 /* The static literal tree. Since the bit lengths are imposed, there is no
95 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
100 /* The static distance tree. (Actually a trivial tree since all codes use
124 const ct_data *static_tree; /* static tree or NULL */
127 int elems; /* max number of elements in the tree */
146 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
148 local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
150 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
151 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
169 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
170 /* Send a code of the given tree. c and tree must not have side effects */
173 # define send_code(s, c, tree) \
175 send_bits(s, tree[c].Code, tree[c].Len); }
244 int n; /* iterates over tree elements */
250 /* number of codes at each bit length for an optimal tree */
296 /* Construct the codes of the static literal tree */
304 * tree construction to get a canonical Huffman tree (longest code
309 /* The static distance tree is trivial: */
385 * Initialize the tree data structures for a new zlib stream.
419 int n; /* iterates over tree elements */
432 /* Index within the heap array of least frequent node in the Huffman tree */
439 #define pqremove(s, tree, top) \
443 pqdownheap(s, tree, SMALLEST); \
447 * Compares to subtrees, using the tree depth as tie breaker when
450 #define smaller(tree, n, m, depth) \
451 (tree[n].Freq < tree[m].Freq || \
452 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
455 * Restore the heap property by moving down the tree starting at node k,
460 local void pqdownheap(s, tree, k)
462 ct_data *tree; /* the tree to restore */
470 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
474 if (smaller(tree, v, s->heap[j], s->depth)) break;
479 /* And continue down the tree, setting j to the left son of k */
486 * Compute the optimal bit lengths for a tree and update the total bit length
489 * above are the tree nodes sorted by increasing frequency.
497 tree_desc *desc; /* the tree descriptor */
499 ct_data *tree = desc->dyn_tree;
506 int n, m; /* iterate over the tree elements */
515 * overflow in the case of the bit length tree).
517 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
521 bits = tree[tree[n].Dad].Len + 1;
523 tree[n].Len = (ush)bits;
524 /* We overwrite tree[n].Dad which is no longer needed */
531 f = tree[n].Freq;
544 s->bl_count[bits]--; /* move one leaf down the tree */
563 if ((unsigned) tree[m].Len != (unsigned) bits) {
564 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
565 s->opt_len += ((long)bits - (long)tree[m].Len)
566 *(long)tree[m].Freq;
567 tree[m].Len = (ush)bits;
575 * Generate the codes for a given tree and bit counts (which need not be
578 * the given tree and the field len is set for all tree elements.
579 * OUT assertion: the field code is set for all tree elements of non
582 local void gen_codes (tree, max_code, bl_count)
583 ct_data *tree; /* the tree to decorate */
606 int len = tree[n].Len;
609 tree[n].Code = bi_reverse(next_code[len]++, len);
611 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
612 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
617 * Construct one Huffman tree and assigns the code bit strings and lengths.
619 * IN assertion: the field freq is set for all tree elements.
626 tree_desc *desc; /* the tree descriptor */
628 ct_data *tree = desc->dyn_tree;
642 if (tree[n].Freq != 0) {
646 tree[n].Len = 0;
657 tree[node].Freq = 1;
664 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
667 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
669 /* Construct the Huffman tree by repeatedly combining the least two
672 node = elems; /* next internal node of the tree */
674 pqremove(s, tree, n); /* n = node of least frequency */
681 tree[node].Freq = tree[n].Freq + tree[m].Freq;
684 tree[n].Dad = tree[m].Dad = (ush)node;
686 if (tree == s->bl_tree) {
688 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
693 pqdownheap(s, tree, SMALLEST);
705 gen_codes ((ct_data *)tree, max_code, s->bl_count);
709 * Scan a literal or distance tree to determine the frequencies of the codes
710 * in the bit length tree.
712 local void scan_tree (s, tree, max_code)
714 ct_data *tree; /* the tree to be scanned */
717 int n; /* iterates over all tree elements */
720 int nextlen = tree[0].Len; /* length of next code */
726 tree[max_code+1].Len = (ush)0xffff; /* guard */
729 curlen = nextlen; nextlen = tree[n+1].Len;
754 * Send a literal or distance tree in compressed form, using the codes in
757 local void send_tree (s, tree, max_code)
759 ct_data *tree; /* the tree to be scanned */
762 int n; /* iterates over all tree elements */
765 int nextlen = tree[0].Len; /* length of next code */
770 /* tree[max_code+1].Len = -1; */ /* guard already set */
774 curlen = nextlen; nextlen = tree[n+1].Len;
805 * Construct the Huffman tree for the bit lengths and return the index in
817 /* Build the bit length tree: */
819 /* opt_len now includes the length of the tree representations, except
830 /* Update opt_len to include the bit length tree and counts */
840 * lengths of the bit length codes, the literal tree and the distance tree.
845 int lcodes, dcodes, blcodes; /* number of codes for each tree */
860 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
862 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
863 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
865 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
866 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
951 * the compressed block data, excluding the tree representations.
954 /* Build the bit length tree for the above two trees, and get the index
1057 ct_data *ltree; /* literal tree */
1058 ct_data *dtree; /* distance tree */