Lines Matching defs:tree
13 * Each code tree is stored in a compressed form which is itself
87 /* The static literal tree. Since the bit lengths are imposed, there is no
89 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
94 /* The static distance tree. (Actually a trivial tree since all codes use
118 const ct_data *static_tree; /* static tree or NULL */
121 int elems; /* max number of elements in the tree */
207 * Generate the codes for a given tree and bit counts (which need not be
210 * the given tree and the field len is set for all tree elements.
211 * OUT assertion: the field code is set for all tree elements of non
214 local void gen_codes(ct_data *tree, int max_code, ushf *bl_count)
236 int len = tree[n].Len;
239 tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
241 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
242 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
251 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
252 /* Send a code of the given tree. c and tree must not have side effects */
255 # define send_code(s, c, tree) \
257 send_bits(s, tree[c].Code, tree[c].Len); }
312 int n; /* iterates over tree elements */
318 /* number of codes at each bit length for an optimal tree */
364 /* Construct the codes of the static literal tree */
372 * tree construction to get a canonical Huffman tree (longest code
377 /* The static distance tree is trivial: */
457 int n; /* iterates over tree elements */
470 * Initialize the tree data structures for a new zlib stream.
496 /* Index within the heap array of least frequent node in the Huffman tree */
503 #define pqremove(s, tree, top) \
507 pqdownheap(s, tree, SMALLEST); \
511 * Compares to subtrees, using the tree depth as tie breaker when
514 #define smaller(tree, n, m, depth) \
515 (tree[n].Freq < tree[m].Freq || \
516 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
519 * Restore the heap property by moving down the tree starting at node k,
524 local void pqdownheap(deflate_state *s, ct_data *tree, int k)
531 smaller(tree, s->heap[j + 1], s->heap[j], s->depth)) {
535 if (smaller(tree, v, s->heap[j], s->depth)) break;
540 /* And continue down the tree, setting j to the left son of k */
547 * Compute the optimal bit lengths for a tree and update the total bit length
550 * above are the tree nodes sorted by increasing frequency.
558 ct_data *tree = desc->dyn_tree;
565 int n, m; /* iterate over the tree elements */
574 * overflow in the case of the bit length tree).
576 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
580 bits = tree[tree[n].Dad].Len + 1;
582 tree[n].Len = (ush)bits;
583 /* We overwrite tree[n].Dad which is no longer needed */
590 f = tree[n].Freq;
603 s->bl_count[bits]--; /* move one leaf down the tree */
622 if ((unsigned) tree[m].Len != (unsigned) bits) {
623 Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
624 s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
625 tree[m].Len = (ush)bits;
637 * Construct one Huffman tree and assigns the code bit strings and lengths.
639 * IN assertion: the field freq is set for all tree elements.
646 ct_data *tree = desc->dyn_tree;
660 if (tree[n].Freq != 0) {
664 tree[n].Len = 0;
675 tree[node].Freq = 1;
682 /* The elements heap[heap_len/2 + 1 .. heap_len] are leaves of the tree,
685 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
687 /* Construct the Huffman tree by repeatedly combining the least two
690 node = elems; /* next internal node of the tree */
692 pqremove(s, tree, n); /* n = node of least frequency */
699 tree[node].Freq = tree[n].Freq + tree[m].Freq;
702 tree[n].Dad = tree[m].Dad = (ush)node;
704 if (tree == s->bl_tree) {
706 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
711 pqdownheap(s, tree, SMALLEST);
723 gen_codes ((ct_data *)tree, max_code, s->bl_count);
727 * Scan a literal or distance tree to determine the frequencies of the codes
728 * in the bit length tree.
730 local void scan_tree(deflate_state *s, ct_data *tree, int max_code)
732 int n; /* iterates over all tree elements */
735 int nextlen = tree[0].Len; /* length of next code */
741 tree[max_code + 1].Len = (ush)0xffff; /* guard */
744 curlen = nextlen; nextlen = tree[n + 1].Len;
769 * Send a literal or distance tree in compressed form, using the codes in
772 local void send_tree(deflate_state *s, ct_data *tree, int max_code)
774 int n; /* iterates over all tree elements */
777 int nextlen = tree[0].Len; /* length of next code */
782 /* tree[max_code + 1].Len = -1; */ /* guard already set */
786 curlen = nextlen; nextlen = tree[n + 1].Len;
817 * Construct the Huffman tree for the bit lengths and return the index in
828 /* Build the bit length tree: */
830 /* opt_len now includes the length of the tree representations, except the
841 /* Update opt_len to include the bit length tree and counts */
851 * lengths of the bit length codes, the literal tree and the distance tree.
870 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
872 send_tree(s, (ct_data *)s->dyn_ltree, lcodes - 1); /* literal tree */
873 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
875 send_tree(s, (ct_data *)s->dyn_dtree, dcodes - 1); /* distance tree */
876 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
1042 * the compressed block data, excluding the tree representations.
1045 /* Build the bit length tree for the above two trees, and get the index