• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/xnu-2422.115.4/libkern/zlib/

Lines Matching defs:tree

39  *      Each code tree is stored in a compressed form which is itself
118 /* The static literal tree. Since the bit lengths are imposed, there is no
120 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
125 /* The static distance tree. (Actually a trivial tree since all codes use
149 const ct_data *static_tree; /* static tree or NULL */
152 int elems; /* max number of elements in the tree */
171 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
173 local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
175 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
176 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
194 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
195 /* Send a code of the given tree. c and tree must not have side effects */
198 # define send_code(s, c, tree) \
200 send_bits(s, tree[c].Code, tree[c].Len); }
269 int n; /* iterates over tree elements */
275 /* number of codes at each bit length for an optimal tree */
319 /* Construct the codes of the static literal tree */
327 * tree construction to get a canonical Huffman tree (longest code
332 /* The static distance tree is trivial: */
407 * Initialize the tree data structures for a new zlib stream.
441 int n; /* iterates over tree elements */
454 /* Index within the heap array of least frequent node in the Huffman tree */
461 #define pqremove(s, tree, top) \
465 pqdownheap(s, tree, SMALLEST); \
469 * Compares to subtrees, using the tree depth as tie breaker when
472 #define smaller(tree, n, m, depth) \
473 (tree[n].Freq < tree[m].Freq || \
474 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
477 * Restore the heap property by moving down the tree starting at node k,
482 local void pqdownheap(s, tree, k)
484 ct_data *tree; /* the tree to restore */
492 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
496 if (smaller(tree, v, s->heap[j], s->depth)) break;
501 /* And continue down the tree, setting j to the left son of k */
508 * Compute the optimal bit lengths for a tree and update the total bit length
511 * above are the tree nodes sorted by increasing frequency.
519 tree_desc *desc; /* the tree descriptor */
521 ct_data *tree = desc->dyn_tree;
528 int n, m; /* iterate over the tree elements */
537 * overflow in the case of the bit length tree).
539 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
543 bits = tree[tree[n].Dad].Len + 1;
545 tree[n].Len = (ush)bits;
546 /* We overwrite tree[n].Dad which is no longer needed */
553 f = tree[n].Freq;
566 s->bl_count[bits]--; /* move one leaf down the tree */
585 if ((unsigned) tree[m].Len != (unsigned) bits) {
586 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
587 s->opt_len += ((long)bits - (long)tree[m].Len)
588 *(long)tree[m].Freq;
589 tree[m].Len = (ush)bits;
597 * Generate the codes for a given tree and bit counts (which need not be
600 * the given tree and the field len is set for all tree elements.
601 * OUT assertion: the field code is set for all tree elements of non
604 local void gen_codes (tree, max_code, bl_count)
605 ct_data *tree; /* the tree to decorate */
628 int len = tree[n].Len;
631 tree[n].Code = bi_reverse(next_code[len]++, len);
633 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
634 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
639 * Construct one Huffman tree and assigns the code bit strings and lengths.
641 * IN assertion: the field freq is set for all tree elements.
648 tree_desc *desc; /* the tree descriptor */
650 ct_data *tree = desc->dyn_tree;
664 if (tree[n].Freq != 0) {
668 tree[n].Len = 0;
679 tree[node].Freq = 1;
686 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
689 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
691 /* Construct the Huffman tree by repeatedly combining the least two
694 node = elems; /* next internal node of the tree */
696 pqremove(s, tree, n); /* n = node of least frequency */
703 tree[node].Freq = tree[n].Freq + tree[m].Freq;
706 tree[n].Dad = tree[m].Dad = (ush)node;
708 if (tree == s->bl_tree) {
710 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
715 pqdownheap(s, tree, SMALLEST);
727 gen_codes ((ct_data *)tree, max_code, s->bl_count);
731 * Scan a literal or distance tree to determine the frequencies of the codes
732 * in the bit length tree.
734 local void scan_tree (s, tree, max_code)
736 ct_data *tree; /* the tree to be scanned */
739 int n; /* iterates over all tree elements */
742 int nextlen = tree[0].Len; /* length of next code */
748 tree[max_code+1].Len = (ush)0xffff; /* guard */
751 curlen = nextlen; nextlen = tree[n+1].Len;
776 * Send a literal or distance tree in compressed form, using the codes in
779 local void send_tree (s, tree, max_code)
781 ct_data *tree; /* the tree to be scanned */
784 int n; /* iterates over all tree elements */
787 int nextlen = tree[0].Len; /* length of next code */
792 /* tree[max_code+1].Len = -1; */ /* guard already set */
796 curlen = nextlen; nextlen = tree[n+1].Len;
827 * Construct the Huffman tree for the bit lengths and return the index in
839 /* Build the bit length tree: */
841 /* opt_len now includes the length of the tree representations, except
852 /* Update opt_len to include the bit length tree and counts */
862 * lengths of the bit length codes, the literal tree and the distance tree.
867 int lcodes, dcodes, blcodes; /* number of codes for each tree */
882 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
884 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
885 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
887 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
888 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
973 * the compressed block data, excluding the tree representations.
976 /* Build the bit length tree for the above two trees, and get the index
1101 ct_data *ltree; /* literal tree */
1102 ct_data *dtree; /* distance tree */