Lines Matching refs: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 */
140 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
142 local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
144 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
145 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
161 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
162 /* Send a code of the given tree. c and tree must not have side effects */
165 # define send_code(s, c, tree) \
167 send_bits(s, tree[c].Code, tree[c].Len); }
236 int n; /* iterates over tree elements */
242 /* number of codes at each bit length for an optimal tree */
288 /* Construct the codes of the static literal tree */
296 * tree construction to get a canonical Huffman tree (longest code
301 /* The static distance tree is trivial: */
377 * Initialize the tree data structures for a new zlib stream.
410 int n; /* iterates over tree elements */
423 /* Index within the heap array of least frequent node in the Huffman tree */
430 #define pqremove(s, tree, top) \
434 pqdownheap(s, tree, SMALLEST); \
438 * Compares to subtrees, using the tree depth as tie breaker when
441 #define smaller(tree, n, m, depth) \
442 (tree[n].Freq < tree[m].Freq || \
443 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
446 * Restore the heap property by moving down the tree starting at node k,
451 local void pqdownheap(s, tree, k)
453 ct_data *tree; /* the tree to restore */
461 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
465 if (smaller(tree, v, s->heap[j], s->depth)) break;
470 /* And continue down the tree, setting j to the left son of k */
477 * Compute the optimal bit lengths for a tree and update the total bit length
480 * above are the tree nodes sorted by increasing frequency.
488 tree_desc *desc; /* the tree descriptor */
490 ct_data *tree = desc->dyn_tree;
497 int n, m; /* iterate over the tree elements */
506 * overflow in the case of the bit length tree).
508 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
512 bits = tree[tree[n].Dad].Len + 1;
514 tree[n].Len = (ush)bits;
515 /* We overwrite tree[n].Dad which is no longer needed */
522 f = tree[n].Freq;
535 s->bl_count[bits]--; /* move one leaf down the tree */
554 if ((unsigned) tree[m].Len != (unsigned) bits) {
555 Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
556 s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
557 tree[m].Len = (ush)bits;
565 * Generate the codes for a given tree and bit counts (which need not be
568 * the given tree and the field len is set for all tree elements.
569 * OUT assertion: the field code is set for all tree elements of non
572 local void gen_codes (tree, max_code, bl_count)
573 ct_data *tree; /* the tree to decorate */
597 int len = tree[n].Len;
600 tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
602 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
603 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
608 * Construct one Huffman tree and assigns the code bit strings and lengths.
610 * IN assertion: the field freq is set for all tree elements.
617 tree_desc *desc; /* the tree descriptor */
619 ct_data *tree = desc->dyn_tree;
633 if (tree[n].Freq != 0) {
637 tree[n].Len = 0;
648 tree[node].Freq = 1;
655 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
658 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
660 /* Construct the Huffman tree by repeatedly combining the least two
663 node = elems; /* next internal node of the tree */
665 pqremove(s, tree, n); /* n = node of least frequency */
672 tree[node].Freq = tree[n].Freq + tree[m].Freq;
675 tree[n].Dad = tree[m].Dad = (ush)node;
677 if (tree == s->bl_tree) {
679 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
684 pqdownheap(s, tree, SMALLEST);
696 gen_codes ((ct_data *)tree, max_code, s->bl_count);
700 * Scan a literal or distance tree to determine the frequencies of the codes
701 * in the bit length tree.
703 local void scan_tree (s, tree, max_code)
705 ct_data *tree; /* the tree to be scanned */
708 int n; /* iterates over all tree elements */
711 int nextlen = tree[0].Len; /* length of next code */
717 tree[max_code+1].Len = (ush)0xffff; /* guard */
720 curlen = nextlen; nextlen = tree[n+1].Len;
745 * Send a literal or distance tree in compressed form, using the codes in
748 local void send_tree (s, tree, max_code)
750 ct_data *tree; /* the tree to be scanned */
753 int n; /* iterates over all tree elements */
756 int nextlen = tree[0].Len; /* length of next code */
761 /* tree[max_code+1].Len = -1; */ /* guard already set */
765 curlen = nextlen; nextlen = tree[n+1].Len;
796 * Construct the Huffman tree for the bit lengths and return the index in
808 /* Build the bit length tree: */
810 /* opt_len now includes the length of the tree representations, except
821 /* Update opt_len to include the bit length tree and counts */
831 * lengths of the bit length codes, the literal tree and the distance tree.
836 int lcodes, dcodes, blcodes; /* number of codes for each tree */
851 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
853 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
854 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
856 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
857 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
937 * the compressed block data, excluding the tree representations.
940 /* Build the bit length tree for the above two trees, and get the index
1045 const ct_data *ltree; /* literal tree */
1046 const ct_data *dtree; /* distance tree */