Lines Matching full:tree
13 * Each code tree is stored in a compressed form which is itself
88 /* The static literal tree. Since the bit lengths are imposed, there is no
90 * The codes 286 and 287 are needed to build a canonical tree (see zlib_tr_init
95 /* The static distance tree. (Actually a trivial tree since all codes use
115 const ct_data *static_tree; /* static tree or NULL */
118 int elems; /* max number of elements in the tree */
137 static void pqdownheap (deflate_state *s, ct_data *tree, int k);
139 static void gen_codes (ct_data *tree, int max_code, ush *bl_count);
141 static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
142 static void send_tree (deflate_state *s, ct_data *tree, int max_code);
156 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) argument
157 /* Send a code of the given tree. c and tree must not have side effects */
160 # define send_code(s, c, tree) \ argument
162 send_bits(s, tree[c].Code, tree[c].Len); }
228 int n; /* iterates over tree elements */ in tr_static_init()
234 /* number of codes at each bit length for an optimal tree */ in tr_static_init()
271 /* Construct the codes of the static literal tree */ in tr_static_init()
279 * tree construction to get a canonical Huffman tree (longest code in tr_static_init()
284 /* The static distance tree is trivial: */ in tr_static_init()
293 * Initialize the tree data structures for a new zlib stream.
330 int n; /* iterates over tree elements */ in init_block()
343 /* Index within the heap array of least frequent node in the Huffman tree */
350 #define pqremove(s, tree, top) \ argument
354 pqdownheap(s, tree, SMALLEST); \
358 * Compares to subtrees, using the tree depth as tie breaker when
361 #define smaller(tree, n, m, depth) \ argument
362 (tree[n].Freq < tree[m].Freq || \
363 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
366 * Restore the heap property by moving down the tree starting at node k,
373 ct_data *tree, /* the tree to restore */ in pqdownheap() argument
382 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { in pqdownheap()
386 if (smaller(tree, v, s->heap[j], s->depth)) break; in pqdownheap()
391 /* And continue down the tree, setting j to the left son of k */ in pqdownheap()
398 * Compute the optimal bit lengths for a tree and update the total bit length
401 * above are the tree nodes sorted by increasing frequency.
409 tree_desc *desc /* the tree descriptor */ in gen_bitlen()
412 ct_data *tree = desc->dyn_tree; in gen_bitlen() local
419 int n, m; /* iterate over the tree elements */ in gen_bitlen()
428 * overflow in the case of the bit length tree). in gen_bitlen()
430 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ in gen_bitlen()
434 bits = tree[tree[n].Dad].Len + 1; in gen_bitlen()
436 tree[n].Len = (ush)bits; in gen_bitlen()
437 /* We overwrite tree[n].Dad which is no longer needed */ in gen_bitlen()
444 f = tree[n].Freq; in gen_bitlen()
457 s->bl_count[bits]--; /* move one leaf down the tree */ in gen_bitlen()
476 if (tree[m].Len != (unsigned) bits) { in gen_bitlen()
477 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); in gen_bitlen()
478 s->opt_len += ((long)bits - (long)tree[m].Len) in gen_bitlen()
479 *(long)tree[m].Freq; in gen_bitlen()
480 tree[m].Len = (ush)bits; in gen_bitlen()
488 * Generate the codes for a given tree and bit counts (which need not be
491 * the given tree and the field len is set for all tree elements.
492 * OUT assertion: the field code is set for all tree elements of non
496 ct_data *tree, /* the tree to decorate */ in gen_codes() argument
520 int len = tree[n].Len; in gen_codes()
523 tree[n].Code = bi_reverse(next_code[len]++, len); in gen_codes()
525 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", in gen_codes()
526 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); in gen_codes()
531 * Construct one Huffman tree and assigns the code bit strings and lengths.
533 * IN assertion: the field freq is set for all tree elements.
540 tree_desc *desc /* the tree descriptor */ in build_tree()
543 ct_data *tree = desc->dyn_tree; in build_tree() local
557 if (tree[n].Freq != 0) { in build_tree()
561 tree[n].Len = 0; in build_tree()
572 tree[node].Freq = 1; in build_tree()
579 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, in build_tree()
582 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); in build_tree()
584 /* Construct the Huffman tree by repeatedly combining the least two in build_tree()
587 node = elems; /* next internal node of the tree */ in build_tree()
589 pqremove(s, tree, n); /* n = node of least frequency */ in build_tree()
596 tree[node].Freq = tree[n].Freq + tree[m].Freq; in build_tree()
598 tree[n].Dad = tree[m].Dad = (ush)node; in build_tree()
600 if (tree == s->bl_tree) { in build_tree()
602 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); in build_tree()
607 pqdownheap(s, tree, SMALLEST); in build_tree()
619 gen_codes ((ct_data *)tree, max_code, s->bl_count); in build_tree()
623 * Scan a literal or distance tree to determine the frequencies of the codes
624 * in the bit length tree.
628 ct_data *tree, /* the tree to be scanned */ in scan_tree() argument
632 int n; /* iterates over all tree elements */ in scan_tree()
635 int nextlen = tree[0].Len; /* length of next code */ in scan_tree()
641 tree[max_code+1].Len = (ush)0xffff; /* guard */ in scan_tree()
644 curlen = nextlen; nextlen = tree[n+1].Len; in scan_tree()
669 * Send a literal or distance tree in compressed form, using the codes in
674 ct_data *tree, /* the tree to be scanned */ in send_tree() argument
678 int n; /* iterates over all tree elements */ in send_tree()
681 int nextlen = tree[0].Len; /* length of next code */ in send_tree()
686 /* tree[max_code+1].Len = -1; */ /* guard already set */ in send_tree()
690 curlen = nextlen; nextlen = tree[n+1].Len; in send_tree()
721 * Construct the Huffman tree for the bit lengths and return the index in
734 /* Build the bit length tree: */ in build_bl_tree()
736 /* opt_len now includes the length of the tree representations, except in build_bl_tree()
747 /* Update opt_len to include the bit length tree and counts */ in build_bl_tree()
757 * lengths of the bit length codes, the literal tree and the distance tree.
762 int lcodes, /* number of codes for each tree */ in send_all_trees()
763 int dcodes, /* number of codes for each tree */ in send_all_trees()
764 int blcodes /* number of codes for each tree */ in send_all_trees()
780 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); in send_all_trees()
782 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ in send_all_trees()
783 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); in send_all_trees()
785 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ in send_all_trees()
786 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); in send_all_trees()
881 * the compressed block data, excluding the tree representations.
884 /* Build the bit length tree for the above two trees, and get the index
1020 ct_data *ltree, /* literal tree */
1021 ct_data *dtree /* distance tree */