Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
ZTrees.c
Go to the documentation of this file.
1/* @(#)root/zip:$Id$ */
2/* Author: */
3/*
4
5 Copyright (C) 1990-1993 Mark Adler, Richard B. Wales, Jean-loup Gailly,
6 Kai Uwe Rommel and Igor Mandrichenko.
7 For conditions of distribution and use, see copyright notice in zlib.h
8
9 */
10#include "Bits.h"
11
12/*
13 * trees.c by Jean-loup Gailly
14 *
15 * This is a new version of im_ctree.c originally written by Richard B. Wales
16 * for the defunct implosion method.
17 *
18 * PURPOSE
19 *
20 * Encode various sets of source values using variable-length
21 * binary code trees.
22 *
23 * DISCUSSION
24 *
25 * The PKZIP "deflation" process uses several Huffman trees. The more
26 * common source values are represented by shorter bit sequences.
27 *
28 * Each code tree is stored in the ZIP file in a compressed form
29 * which is itself a Huffman encoding of the lengths of
30 * all the code strings (in ascending order by source values).
31 * The actual code strings are reconstructed from the lengths in
32 * the UNZIP process, as described in the "application note"
33 * (APPNOTE.TXT) distributed as part of PKWARE's PKZIP program.
34 *
35 * REFERENCES
36 *
37 * Lynch, Thomas J.
38 * Data Compression: Techniques and Applications, pp. 53-55.
39 * Lifetime Learning Publications, 1985. ISBN 0-534-03418-7.
40 *
41 * Storer, James A.
42 * Data Compression: Methods and Theory, pp. 49-50.
43 * Computer Science Press, 1988. ISBN 0-7167-8156-5.
44 *
45 * Sedgewick, R.
46 * Algorithms, p290.
47 * Addison-Wesley, 1983. ISBN 0-201-06672-6.
48 *
49 * INTERFACE
50 *
51 * void ct_init (ush *attr, int *method)
52 * Allocate the match buffer, initialize the various tables and save
53 * the location of the internal file attribute (ascii/binary) and
54 * method (DEFLATE/STORE)
55 *
56 * void ct_tally (int dist, int lc);
57 * Save the match info and tally the frequency counts.
58 *
59 * long flush_block (char *buf, ulg stored_len, int eof)
60 * Determine the best encoding for the current block: dynamic trees,
61 * static trees or store, and output the encoded block to the zip
62 * file. Returns the total compressed length for the file so far.
63 *
64 */
65
66#include <ctype.h>
67/* #include "zip.h" */
68/* #include "ZIP.h" */
69
70/* ===========================================================================
71 * Constants
72 */
73
74#define MAX_BITS 15
75/* All codes must not exceed MAX_BITS bits */
76
77#define MAX_BL_BITS 7
78/* Bit length codes must not exceed MAX_BL_BITS bits */
79
80#define LENGTH_CODES 29
81/* number of length codes, not counting the special END_BLOCK code */
82
83#define LITERALS 256
84/* number of literal bytes 0..255 */
85
86#define END_BLOCK 256
87/* end of block literal code */
88
89#define L_CODES (LITERALS+1+LENGTH_CODES)
90/* number of Literal or Length codes, including the END_BLOCK code */
91
92#define D_CODES 30
93/* number of distance codes */
94
95#define BL_CODES 19
96/* number of codes used to transfer the bit lengths */
97
98
99local int near extra_lbits[LENGTH_CODES] /* extra bits for each length code */
100= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
101
102local int near extra_dbits[D_CODES] /* extra bits for each distance code */
103= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
104
105local int near extra_blbits[BL_CODES]/* extra bits for each bit length code */
106= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
107
108#define STORED_BLOCK 0
109#define STATIC_TREES 1
110#define DYN_TREES 2
111/* The three kinds of block type */
112
113#ifndef LIT_BUFSIZE
114# ifdef SMALL_MEM
115# define LIT_BUFSIZE 0x2000
116# else
117# ifdef MEDIUM_MEM
118# define LIT_BUFSIZE 0x4000
119# else
120# define LIT_BUFSIZE 0x8000
121# endif
122# endif
123#endif
124#define DIST_BUFSIZE LIT_BUFSIZE
125/* Sizes of match buffers for literals/lengths and distances. There are
126 * 4 reasons for limiting LIT_BUFSIZE to 64K:
127 * - frequencies can be kept in 16 bit counters
128 * - if compression is not successful for the first block, all input data is
129 * still in the window so we can still emit a stored block even when input
130 * comes from standard input. (This can also be done for all blocks if
131 * LIT_BUFSIZE is not greater than 32K.)
132 * - if compression is not successful for a file smaller than 64K, we can
133 * even emit a stored file instead of a stored block (saving 5 bytes).
134 * - creating new Huffman trees less frequently may not provide fast
135 * adaptation to changes in the input data statistics. (Take for
136 * example a binary file with poorly compressible code followed by
137 * a highly compressible string table.) Smaller buffer sizes give
138 * fast adaptation but have of course the overhead of transmitting trees
139 * more frequently.
140 * - I can't count above 4
141 * The current code is general and allows DIST_BUFSIZE < LIT_BUFSIZE (to save
142 * memory at the expense of compression). Some optimizations would be possible
143 * if we rely on DIST_BUFSIZE == LIT_BUFSIZE.
144 */
145
146#define REP_3_6 16
147/* repeat previous bit length 3-6 times (2 bits of repeat count) */
148
149#define REPZ_3_10 17
150/* repeat a zero length 3-10 times (3 bits of repeat count) */
151
152#define REPZ_11_138 18
153/* repeat a zero length 11-138 times (7 bits of repeat count) */
154
155/* ===========================================================================
156 * Local data
157 */
158
159/* Data structure describing a single value and its code string. */
160typedef struct ct_data {
161 union {
162 ush freq; /* frequency count */
163 ush code; /* bit string */
164 } fc;
165 union {
166 ush dad; /* father node in Huffman tree */
167 ush len; /* length of bit string */
168 } dl;
170
171#define Freq fc.freq
172#define Code fc.code
173#define Dad dl.dad
174#define Len dl.len
175
176#define HEAP_SIZE (2*L_CODES+1)
177/* maximum heap size */
178
180= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
181/* The lengths of the bit length codes are sent in order of decreasing
182 * probability, to avoid transmitting the lengths for unused bit length codes.
183 */
184
185typedef struct tree_desc {
186 ct_data near *dyn_tree; /* the dynamic tree */
187 ct_data near *static_tree; /* corresponding static tree or NULL */
188 int near *extra_bits; /* extra bits for each code or NULL */
189 int extra_base; /* base index for extra_bits */
190 int elems; /* max number of elements in the tree */
191 int max_length; /* max bit length for the codes */
192 int max_code; /* largest code with non zero frequency */
194
196 ct_data near dyn_ltree[HEAP_SIZE]; /* literal and length tree */
197 ct_data near dyn_dtree[2*D_CODES+1]; /* distance tree */
198
200 /* The static literal tree. Since the bit lengths are imposed, there is no
201 * need for the L_CODES extra codes used during heap construction. However
202 * The codes 286 and 287 are needed to build a canonical tree (see ct_init
203 * below).
204 */
205
207 /* The static distance tree. (Actually a trivial tree since all codes use
208 * 5 bits.)
209 */
210
212 /* Huffman tree for the bit lengths */
213
215
217
219
220
222 /* number of codes at each bit length for an optimal tree */
223
224 int near heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
225 int heap_len; /* number of elements in the heap */
226 int heap_max; /* element of largest frequency */
227 /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
228 * The same heap array is used to build all trees.
229 */
230
232 /* Depth of each subtree used as tie breaker for trees of equal frequency */
233
235 /* length code for each normalized match length (0 == MIN_MATCH) */
236
238 /* distance codes. The first 256 values correspond to the distances
239 * 3 .. 258, the last 256 values correspond to the top 8 bits of
240 * the 15 bit distances.
241 */
242
244 /* First normalized length for each code (0 = MIN_MATCH) */
245
247 /* First normalized distance for each code (0 = distance of 1) */
248
249#ifndef DYN_ALLOC
250 uch far l_buf[LIT_BUFSIZE]; /* buffer for literals/lengths */
251 ush far d_buf[DIST_BUFSIZE]; /* buffer for distances */
252#else
253 uch far *l_buf;
254 ush far *d_buf;
255#endif
256
258 /* flag_buf is a bit array distinguishing literals from lengths in
259 * l_buf, and thus indicating the presence or absence of a distance.
260 */
261
262 unsigned last_lit; /* running index in l_buf */
263 unsigned last_dist; /* running index in d_buf */
264 unsigned last_flags; /* running index in flag_buf */
265 uch flags; /* current flags not yet saved in flag_buf */
266 uch flag_bit; /* current bit used in flags */
267 /* bits are filled in flags starting at bit 0 (least significant).
268 * Note: these flags are overkill in the current code since we don't
269 * take advantage of DIST_BUFSIZE == LIT_BUFSIZE.
270 */
271
272 ulg opt_len; /* bit length of current block with optimal trees */
273 ulg static_len; /* bit length of current block with static trees */
274
275 ulg compressed_len; /* total bit length of compressed file */
276
277 ulg input_len; /* total byte length of input file */
278 /* input_len is for debugging only since we can get it by other means. */
279
280 ush *R__file_type; /* pointer to UNKNOWN, BINARY or ASCII */
281 int *R__file_method; /* pointer to DEFLATE or STORE */
282
283};
284
285#include "ThreadLocalStorage.h"
286
287/* ===========================================================================
288 * Allocate the per thread ZTree internal state object
289 */
290TTHREAD_TLS_DECLARE(int,tree_state_isInit);
292
294
295 TTHREAD_TLS_INIT(int,tree_state_isInit,0);
296 TTHREAD_TLS_INIT(tree_internal_state *,tree_state,0);
297 if (!TTHREAD_TLS_GET(int,tree_state_isInit)) {
298 TTHREAD_TLS_SET(int,tree_state_isInit,1);
299 TTHREAD_TLS_SET(tree_internal_state*,tree_state,fcalloc(1,sizeof(tree_internal_state)));
300 }
301 return TTHREAD_TLS_GET(tree_internal_state*,tree_state);
302}
303
304#ifdef DEBUG
305/* extern ulg R__bits_sent; */ /* bit length of the compressed data */
306/* extern ulg R__isize; */ /* byte length of input file */
307#endif
308
309/* extern long R__block_start; */ /* window offset of current block */
310/* extern unsigned near R__strstart; */ /* window offset of current string */
311
312/* ===========================================================================
313 * Local (static) routines in this file.
314 */
315
319local void R__gen_codes OF((tree_internal_state *t_state, ct_data near *tree, int max_code));
321local void R__scan_tree OF((tree_internal_state *t_state, ct_data near *tree, int max_code));
324local void R__send_all_trees OF((bits_internal_state *state, tree_internal_state *t_state, int lcodes, int dcodes, int blcodes));
327
328
329#ifndef DEBUG
330# define send_code(c, tree) R__send_bits(state,tree[c].Code, tree[c].Len)
331/* Send a code of the given tree. c and tree must not have side effects */
332
333#else /* DEBUG */
334# define send_code(c, tree) \
335{ R__error("\ncd %3d ",(c)); \
336R__send_bits(state,tree[c].Code, tree[c].Len); }
337#endif
338
339#define d_code(dist) \
340((dist) < 256 ? t_state->dist_code[dist] : t_state->dist_code[256+((dist)>>7)])
341/* Mapping from a distance to a distance code. dist is the distance - 1 and
342 * must not have side effects. dist_code[256] and dist_code[257] are never
343 * used.
344 */
345
346#define MAX(a,b) (a >= b ? a : b)
347/* the arguments must not have side effects */
348
349void R__tree_desc_init(tree_desc *tree_description,
350 ct_data near *dyn_tree, /* the dynamic tree */
351 ct_data near *static_tree, /* corresponding static tree or NULL */
352 int near *extra_bits, /* extra bits for each code or NULL */
353 int extra_base, /* base index for extra_bits */
354 int elems, /* max number of elements in the tree */
355 int max_length, /* max bit length for the codes */
356 int max_code /* largest code with non zero frequency */
357)
358{
359 tree_description->dyn_tree = dyn_tree;
360 tree_description->static_tree = static_tree;
361 tree_description->extra_bits = extra_bits;
362 tree_description->extra_base = extra_base;
363 tree_description->elems = elems;
364 tree_description->max_length = max_length;
365 tree_description->max_code = max_code;
366}
367
368/* ===========================================================================
369 * Allocate the match buffer, initialize the various tables and save the
370 * location of the internal file attribute (ascii/binary) and method
371 * (DEFLATE/STORE).
372 */
373int R__ct_init(tree_internal_state *t_state, ush *attr, int *method)
374/* ush *attr; pointer to internal file attribute */
375/* int *method; pointer to compression method */
376{
377 int n; /* iterates over tree elements */
378 int bits; /* bit counter */
379 int length; /* length value */
380 int code; /* code value */
381 int dist; /* distance index */
382
383 t_state->R__file_type = attr;
384 t_state->R__file_method = method;
385 t_state->compressed_len = t_state->input_len = 0L;
386
387 if (t_state->static_dtree[0].Len != 0) return 0; /* ct_init already called */
388
389 R__tree_desc_init(&t_state->l_desc, t_state->dyn_ltree, t_state->static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS, 0);
390 R__tree_desc_init(&t_state->d_desc, t_state->dyn_dtree, t_state->static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0);
392#ifdef DYN_ALLOC
393 d_buf = (ush far*) fcalloc(DIST_BUFSIZE, sizeof(ush));
394 l_buf = (uch far*) fcalloc(LIT_BUFSIZE/2, 2);
395 /* Avoid using the value 64K on 16 bit machines */
396 if (l_buf == NULL || d_buf == NULL) {
397 R__error("R__ct_init: out of memory");
398 return 1;
399 }
400#endif
401
402 /* Initialize the mapping length (0..255) -> length code (0..28) */
403 length = 0;
404 for (code = 0; code < LENGTH_CODES-1; code++) {
405 t_state->base_length[code] = length;
406 for (n = 0; n < (1<<extra_lbits[code]); n++) {
407 t_state->length_code[length++] = (uch)code;
408 }
409 }
410 Assert (length == 256, "R__ct_init: length != 256");
411 /* Note that the length 255 (match length 258) can be represented
412 * in two different ways: code 284 + 5 bits or code 285, so we
413 * overwrite length_code[255] to use the best encoding:
414 */
415 t_state->length_code[length-1] = (uch)code;
416
417 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
418 dist = 0;
419 for (code = 0 ; code < 16; code++) {
420 t_state->base_dist[code] = dist;
421 for (n = 0; n < (1<<extra_dbits[code]); n++) {
422 t_state->dist_code[dist++] = (uch)code;
423 }
424 }
425 Assert (dist == 256, "R__ct_init: dist != 256");
426 dist >>= 7; /* from now on, all distances are divided by 128 */
427 for ( ; code < D_CODES; code++) {
428 t_state->base_dist[code] = dist << 7;
429 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
430 t_state->dist_code[256 + dist++] = (uch)code;
431 }
432 }
433 Assert (dist == 256, "R__ct_init: 256+dist != 512");
434
435 /* Construct the codes of the static literal tree */
436 for (bits = 0; bits <= MAX_BITS; bits++) t_state->bl_count[bits] = 0;
437 n = 0;
438 while (n <= 143) t_state->static_ltree[n++].Len = 8, t_state->bl_count[8]++;
439 while (n <= 255) t_state->static_ltree[n++].Len = 9, t_state->bl_count[9]++;
440 while (n <= 279) t_state->static_ltree[n++].Len = 7, t_state->bl_count[7]++;
441 while (n <= 287) t_state->static_ltree[n++].Len = 8, t_state->bl_count[8]++;
442 /* Codes 286 and 287 do not exist, but we must include them in the
443 * tree construction to get a canonical Huffman tree (longest code
444 * all ones)
445 */
446 R__gen_codes(t_state,(ct_data near *)t_state->static_ltree, L_CODES+1);
447
448 /* The static distance tree is trivial: */
449 for (n = 0; n < D_CODES; n++) {
450 t_state->static_dtree[n].Len = 5;
451 t_state->static_dtree[n].Code = R__bi_reverse(n, 5);
452 }
453
454 /* Initialize the first block of the first file: */
455 R__init_block(t_state);
456 return 0;
457}
458
459/* ===========================================================================
460 * Initialize a new block.
461 */
463{
464 int n; /* iterates over tree elements */
465
466 /* Initialize the trees. */
467 for (n = 0; n < L_CODES; n++) t_state->dyn_ltree[n].Freq = 0;
468 for (n = 0; n < D_CODES; n++) t_state->dyn_dtree[n].Freq = 0;
469 for (n = 0; n < BL_CODES; n++) t_state->bl_tree[n].Freq = 0;
470
471 t_state->dyn_ltree[END_BLOCK].Freq = 1;
472 t_state->opt_len = t_state->static_len = 0L;
473 t_state->last_lit = t_state->last_dist = t_state->last_flags = 0;
474 t_state->flags = 0; t_state->flag_bit = 1;
475}
476
477#define SMALLEST 1
478/* Index within the heap array of least frequent node in the Huffman tree */
479
480
481/* ===========================================================================
482 * Remove the smallest element from the heap and recreate the heap with
483 * one less element. Updates heap and heap_len.
484 */
485#define pqremove(tree, top) \
486{\
487top = t_state->heap[SMALLEST]; \
488t_state->heap[SMALLEST] = t_state->heap[t_state->heap_len--]; \
489R__pqdownheap(t_state, tree, SMALLEST); \
490}
491
492/* ===========================================================================
493 * Compares to subtrees, using the tree depth as tie breaker when
494 * the subtrees have equal frequency. This minimizes the worst case length.
495 */
496#define smaller(tree, n, m) \
497(tree[n].Freq < tree[m].Freq || \
498(tree[n].Freq == tree[m].Freq && t_state->depth[n] <= t_state->depth[m]))
499
500/* ===========================================================================
501 * Restore the heap property by moving down the tree starting at node k,
502 * exchanging a node with the smallest of its two sons if necessary, stopping
503 * when the heap property is re-established (each father smaller than its
504 * two sons).
505 */
507/* ct_data near *tree; the tree to restore */
508/* int k; node to move down */
509{
510 int v = t_state->heap[k];
511 int j = k << 1; /* left son of k */
512 int htemp; /* required because of bug in SASC compiler */
513
514 while (j <= t_state->heap_len) {
515 /* Set j to the smallest of the two sons: */
516 if (j < t_state->heap_len && smaller(tree, t_state->heap[j+1], t_state->heap[j])) j++;
517
518 /* Exit if v is smaller than both sons */
519 htemp = t_state->heap[j];
520 if (smaller(tree, v, htemp)) break;
521
522 /* Exchange v with the smallest son */
523 t_state->heap[k] = htemp;
524 k = j;
525
526 /* And continue down the tree, setting j to the left son of k */
527 j <<= 1;
528 }
529 t_state->heap[k] = v;
530}
531
532/* ===========================================================================
533 * Compute the optimal bit lengths for a tree and update the total bit length
534 * for the current block.
535 * IN assertion: the fields freq and dad are set, heap[heap_max] and
536 * above are the tree nodes sorted by increasing frequency.
537 * OUT assertions: the field len is set to the optimal bit length, the
538 * array bl_count contains the frequencies for each bit length.
539 * The length opt_len is updated; static_len is also updated if stree is
540 * not null.
541 */
543/* tree_desc near *desc; the tree descriptor */
544{
545 ct_data near *tree = desc->dyn_tree;
546 int near *extra = desc->extra_bits;
547 int base = desc->extra_base;
548 int max_code = desc->max_code;
549 int max_length = desc->max_length;
550 ct_data near *stree = desc->static_tree;
551 int h; /* heap index */
552 int n, m; /* iterate over the tree elements */
553 int bits; /* bit length */
554 int xbits; /* extra bits */
555 ush f; /* frequency */
556 int overflow = 0; /* number of elements with bit length too large */
557
558 for (bits = 0; bits <= MAX_BITS; bits++) t_state->bl_count[bits] = 0;
559
560 /* In a first pass, compute the optimal bit lengths (which may
561 * overflow in the case of the bit length tree).
562 */
563 tree[t_state->heap[t_state->heap_max]].Len = 0; /* root of the heap */
564
565 for (h = t_state->heap_max+1; h < HEAP_SIZE; h++) {
566 n = t_state->heap[h];
567 bits = tree[tree[n].Dad].Len + 1;
568 if (bits > max_length) bits = max_length, overflow++;
569 tree[n].Len = bits;
570 /* We overwrite tree[n].Dad which is no longer needed */
571
572 if (n > max_code) continue; /* not a leaf node */
573
574 t_state->bl_count[bits]++;
575 xbits = 0;
576 if (n >= base) xbits = extra[n-base];
577 f = tree[n].Freq;
578 t_state->opt_len += (ulg)f * (bits + xbits);
579 if (stree) t_state->static_len += (ulg)f * (stree[n].Len + xbits);
580 }
581 if (overflow == 0) return;
582
583 Trace((stderr,"\nbit length overflow\n"));
584 /* This happens for example on obj2 and pic of the Calgary corpus */
585
586 /* Find the first bit length which could increase: */
587 do {
588 bits = max_length-1;
589 while (t_state->bl_count[bits] == 0) bits--;
590 t_state->bl_count[bits]--; /* move one leaf down the tree */
591 t_state->bl_count[bits+1] += 2; /* move one overflow item as its brother */
592 t_state->bl_count[max_length]--;
593 /* The brother of the overflow item also moves one step up,
594 * but this does not affect bl_count[max_length]
595 */
596 overflow -= 2;
597 } while (overflow > 0);
598
599 /* Now recompute all bit lengths, scanning in increasing frequency.
600 * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
601 * lengths instead of fixing only the wrong ones. This idea is taken
602 * from 'ar' written by Haruhiko Okumura.)
603 */
604 for (bits = max_length; bits != 0; bits--) {
605 n = t_state->bl_count[bits];
606 while (n != 0) {
607 m = t_state->heap[--h];
608 if (m > max_code) continue;
609 if (tree[m].Len != (unsigned) bits) {
610 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
611 t_state->opt_len += ((long)bits-(long)tree[m].Len)*(long)tree[m].Freq;
612 tree[m].Len = bits;
613 }
614 n--;
615 }
616 }
617}
618
619/* ===========================================================================
620 * Generate the codes for a given tree and bit counts (which need not be
621 * optimal).
622 * IN assertion: the array bl_count contains the bit length statistics for
623 * the given tree and the field len is set for all tree elements.
624 * OUT assertion: the field code is set for all tree elements of non
625 * zero code length.
626 */
627local void R__gen_codes (tree_internal_state *t_state, ct_data near *tree, int max_code)
628/* ct_data near *tree; the tree to decorate */
629/* int max_code; largest code with non zero frequency */
630{
631 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
632 ush code = 0; /* running code value */
633 int bits; /* bit index */
634 int n; /* code index */
635
636 /* The distribution counts are first used to generate the code values
637 * without bit reversal.
638 */
639 for (bits = 1; bits <= MAX_BITS; bits++) {
640 next_code[bits] = code = (code + t_state->bl_count[bits-1]) << 1;
641 }
642 /* Check that the bit counts in bl_count are consistent. The last code
643 * must be all ones.
644 */
645 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
646 "inconsistent bit counts");
647 Tracev((stderr,"\nR__gen_codes: max_code %d ", max_code));
648
649 for (n = 0; n <= max_code; n++) {
650 int len = tree[n].Len;
651 if (len == 0) continue;
652 /* Now reverse the bits */
653 tree[n].Code = R__bi_reverse(next_code[len]++, len);
654
655 Tracec(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
656 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
657 }
658}
659
660/* ===========================================================================
661 * Construct one Huffman tree and assigns the code bit strings and lengths.
662 * Update the total bit length for the current block.
663 * IN assertion: the field freq is set for all tree elements.
664 * OUT assertions: the fields len and code are set to the optimal bit length
665 * and corresponding code. The length opt_len is updated; static_len is
666 * also updated if stree is not null. The field max_code is set.
667 */
669/* tree_desc near *desc; the tree descriptor */
670{
671 ct_data near *tree = desc->dyn_tree;
672 ct_data near *stree = desc->static_tree;
673 int elems = desc->elems;
674 int n, m; /* iterate over heap elements */
675 int max_code = -1; /* largest code with non zero frequency */
676 int node = elems; /* next internal node of the tree */
677
678 /* Construct the initial heap, with least frequent element in
679 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
680 * heap[0] is not used.
681 */
682 t_state->heap_len = 0, t_state->heap_max = HEAP_SIZE;
683
684 for (n = 0; n < elems; n++) {
685 if (tree[n].Freq != 0) {
686 t_state->heap[++t_state->heap_len] = max_code = n;
687 t_state->depth[n] = 0;
688 } else {
689 tree[n].Len = 0;
690 }
691 }
692
693 /* The pkzip format requires that at least one distance code exists,
694 * and that at least one bit should be sent even if there is only one
695 * possible code. So to avoid special checks later on we force at least
696 * two codes of non zero frequency.
697 */
698 while (t_state->heap_len < 2) {
699 int new1 = t_state->heap[++t_state->heap_len] = (max_code < 2 ? ++max_code : 0);
700 tree[new1].Freq = 1;
701 t_state->depth[new1] = 0;
702 t_state->opt_len--; if (stree) t_state->static_len -= stree[new1].Len;
703 /* new is 0 or 1 so it does not have extra bits */
704 }
705 desc->max_code = max_code;
706
707 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
708 * establish sub-heaps of increasing lengths:
709 */
710 for (n = t_state->heap_len/2; n >= 1; n--) R__pqdownheap(t_state, tree, n);
711
712 /* Construct the Huffman tree by repeatedly combining the least two
713 * frequent nodes.
714 */
715 do {
716 pqremove(tree, n); /* n = node of least frequency */
717 m = t_state->heap[SMALLEST]; /* m = node of next least frequency */
718
719 t_state->heap[--t_state->heap_max] = n; /* keep the nodes sorted by frequency */
720 t_state->heap[--t_state->heap_max] = m;
721
722 /* Create a new node father of n and m */
723 tree[node].Freq = tree[n].Freq + tree[m].Freq;
724 t_state->depth[node] = (uch) (MAX(t_state->depth[n], t_state->depth[m]) + 1);
725 tree[n].Dad = tree[m].Dad = node;
726#ifdef DUMP_BL_TREE
727 if (tree == t_state->bl_tree) {
728 fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
729 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
730 }
731#endif
732 /* and insert the new node in the heap */
733 t_state->heap[SMALLEST] = node++;
734 R__pqdownheap(t_state, tree, SMALLEST);
735
736 } while (t_state->heap_len >= 2);
737
738 t_state->heap[--t_state->heap_max] = t_state->heap[SMALLEST];
739
740 /* At this point, the fields freq and dad are set. We can now
741 * generate the bit lengths.
742 */
743 R__gen_bitlen(t_state,(tree_desc near *)desc);
744
745 /* The field len is now set, we can generate the bit codes */
746 R__gen_codes (t_state, (ct_data near *)tree, max_code);
747}
748
749/* ===========================================================================
750 * Scan a literal or distance tree to determine the frequencies of the codes
751 * in the bit length tree. Updates opt_len to take into account the repeat
752 * counts. (The contribution of the bit length codes will be added later
753 * during the construction of bl_tree.)
754 */
755local void R__scan_tree (tree_internal_state *t_state, ct_data near *tree, int max_code)
756/* ct_data near *tree; the tree to be scanned */
757/* int max_code; and its largest code of non zero frequency */
758{
759 int n; /* iterates over all tree elements */
760 int prevlen = -1; /* last emitted length */
761 int curlen; /* length of current code */
762 int nextlen = tree[0].Len; /* length of next code */
763 int count = 0; /* repeat count of the current code */
764 int max_count = 7; /* max repeat count */
765 int min_count = 4; /* min repeat count */
766
767 if (nextlen == 0) max_count = 138, min_count = 3;
768 tree[max_code+1].Len = (ush)-1; /* guard */
769
770 for (n = 0; n <= max_code; n++) {
771 curlen = nextlen; nextlen = tree[n+1].Len;
772 if (++count < max_count && curlen == nextlen) {
773 continue;
774 } else if (count < min_count) {
775 t_state->bl_tree[curlen].Freq += count;
776 } else if (curlen != 0) {
777 if (curlen != prevlen) t_state->bl_tree[curlen].Freq++;
778 t_state->bl_tree[REP_3_6].Freq++;
779 } else if (count <= 10) {
780 t_state->bl_tree[REPZ_3_10].Freq++;
781 } else {
782 t_state->bl_tree[REPZ_11_138].Freq++;
783 }
784 count = 0; prevlen = curlen;
785 if (nextlen == 0) {
786 max_count = 138, min_count = 3;
787 } else if (curlen == nextlen) {
788 max_count = 6, min_count = 3;
789 } else {
790 max_count = 7, min_count = 4;
791 }
792 }
793}
794
795/* ===========================================================================
796 * Send a literal or distance tree in compressed form, using the codes in
797 * bl_tree.
798 */
800/* ct_data near *tree; the tree to be scanned */
801/* int max_code; and its largest code of non zero frequency */
802{
803 int n; /* iterates over all tree elements */
804 int prevlen = -1; /* last emitted length */
805 int curlen; /* length of current code */
806 int nextlen = tree[0].Len; /* length of next code */
807 int count = 0; /* repeat count of the current code */
808 int max_count = 7; /* max repeat count */
809 int min_count = 4; /* min repeat count */
810
811 /* tree[max_code+1].Len = -1; */ /* guard already set */
812 if (nextlen == 0) max_count = 138, min_count = 3;
813
814 for (n = 0; n <= max_code; n++) {
815 curlen = nextlen; nextlen = tree[n+1].Len;
816 if (++count < max_count && curlen == nextlen) {
817 continue;
818 } else if (count < min_count) {
819 do { send_code(curlen, t_state->bl_tree); } while (--count != 0);
820
821 } else if (curlen != 0) {
822 if (curlen != prevlen) {
823 send_code(curlen, t_state->bl_tree); count--;
824 }
825 Assert(count >= 3 && count <= 6, " 3_6?");
826 send_code(REP_3_6, t_state->bl_tree); R__send_bits(state,count-3, 2);
827
828 } else if (count <= 10) {
829 send_code(REPZ_3_10, t_state->bl_tree); R__send_bits(state,count-3, 3);
830
831 } else {
832 send_code(REPZ_11_138, t_state->bl_tree); R__send_bits(state,count-11, 7);
833 }
834 count = 0; prevlen = curlen;
835 if (nextlen == 0) {
836 max_count = 138, min_count = 3;
837 } else if (curlen == nextlen) {
838 max_count = 6, min_count = 3;
839 } else {
840 max_count = 7, min_count = 4;
841 }
842 }
843}
844
845/* ===========================================================================
846 * Construct the Huffman tree for the bit lengths and return the index in
847 * bl_order of the last bit length code to send.
848 */
850{
851 int max_blindex; /* index of last bit length code of non zero freq */
852
853 /* Determine the bit length frequencies for literal and distance trees */
854 R__scan_tree(t_state,(ct_data near *)t_state->dyn_ltree, t_state->l_desc.max_code);
855 R__scan_tree(t_state,(ct_data near *)t_state->dyn_dtree, t_state->d_desc.max_code);
856
857 /* Build the bit length tree: */
858 R__build_tree(t_state,(tree_desc near *)(&t_state->bl_desc));
859 /* opt_len now includes the length of the tree representations, except
860 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
861 */
862
863 /* Determine the number of bit length codes to send. The pkzip format
864 * requires that at least 4 bit length codes be sent. (appnote.txt says
865 * 3 but the actual value used is 4.)
866 */
867 for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
868 if (t_state->bl_tree[bl_order[max_blindex]].Len != 0) break;
869 }
870 /* Update opt_len to include the bit length tree and counts */
871 t_state->opt_len += 3*(max_blindex+1) + 5+5+4;
872 Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", t_state->opt_len, t_state->static_len));
873
874 return max_blindex;
875}
876
877/* ===========================================================================
878 * Send the header for a block using dynamic Huffman trees: the counts, the
879 * lengths of the bit length codes, the literal tree and the distance tree.
880 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
881 */
882local void R__send_all_trees(bits_internal_state *state, tree_internal_state *t_state, int lcodes, int dcodes, int blcodes)
883/* int lcodes, dcodes, blcodes; number of codes for each tree */
884{
885 int rank; /* index in bl_order */
886
887 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
888 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
889 "too many codes");
890 Tracev((stderr, "\nbl counts: "));
891 R__send_bits(state,lcodes-257, 5);
892 /* not +255 as stated in appnote.txt 1.93a or -256 in 2.04c */
893 R__send_bits(state,dcodes-1, 5);
894 R__send_bits(state,blcodes-4, 4); /* not -3 as stated in appnote.txt */
895 for (rank = 0; rank < blcodes; rank++) {
896 Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
897 R__send_bits(state,t_state->bl_tree[bl_order[rank]].Len, 3);
898 }
899 Tracev((stderr, "\nbl tree: sent %ld", R__bits_sent));
900
901 R__send_tree(state,t_state,(ct_data near *)t_state->dyn_ltree, lcodes-1); /* send the literal tree */
902 Tracev((stderr, "\nlit tree: sent %ld", R__bits_sent));
903
904 R__send_tree(state,t_state,(ct_data near *)t_state->dyn_dtree, dcodes-1); /* send the distance tree */
905 Tracev((stderr, "\ndist tree: sent %ld", R__bits_sent));
906}
907
908/* ===========================================================================
909 * Determine the best encoding for the current block: dynamic trees, static
910 * trees or store, and output the encoded block to the zip file. This function
911 * returns the total compressed length for the file so far.
912 */
913ulg R__flush_block(bits_internal_state *state, char *buf, ulg stored_len, int eof, int *errorflag)
914/* char *buf; input block, or NULL if too old */
915/* ulg stored_len; length of input block */
916/* int eof; true if this is the last block for a file */
917{
918 tree_internal_state *t_state = state->t_state;
919 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
920 int max_blindex; /* index of last bit length code of non zero freq */
921
922 t_state->flag_buf[t_state->last_flags] = t_state->flags; /* Save the flags for the last 8 items */
923
924 /* Check if the file is ascii or binary */
925 if (*t_state->R__file_type == (ush)UNKNOWN) R__set_file_type(t_state);
926
927 /* Construct the literal and distance trees */
928 R__build_tree(t_state,(tree_desc near *)(&t_state->l_desc));
929 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", t_state->opt_len, t_state->static_len));
930
931 R__build_tree(t_state,(tree_desc near *)(&t_state->d_desc));
932 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", opt_len, static_len));
933 /* At this point, opt_len and static_len are the total bit lengths of
934 * the compressed block data, excluding the tree representations.
935 */
936
937 /* Build the bit length tree for the above two trees, and get the index
938 * in bl_order of the last bit length code to send.
939 */
940 max_blindex = R__build_bl_tree(t_state);
941
942 /* Determine the best encoding. Compute first the block length in bytes */
943 opt_lenb = (t_state->opt_len+3+7)>>3;
944 static_lenb = (t_state->static_len+3+7)>>3;
945 t_state->input_len += stored_len; /* for debugging only */
946
947 Trace((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
948 opt_lenb, opt_len, static_lenb, static_len, stored_len,
949 last_lit, last_dist));
950
951 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
952
953#ifndef PGP /* PGP can't handle stored blocks */
954 /* If compression failed and this is the first and last block,
955 * and if the zip file can be seeked (to rewrite the local header),
956 * the whole file is transformed into a stored file:
957 */
958#ifdef FORCE_METHOD
959 if (gCompressionLevel == 1 && eof && compressed_len == 0L) { /* force stored file */
960#else
961 if (stored_len <= opt_lenb && eof && t_state->compressed_len == 0L && 0) {
962#endif
963 /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
964 if (buf == (char *) NULL) { R__error ("block vanished"); *errorflag = 1; }
965
966 R__copy_block(state, buf, (unsigned)stored_len, 0); /* without header */
967 t_state->compressed_len = stored_len << 3;
968 *t_state->R__file_method = STORE;
969 } else
970#endif /* PGP */
971
972#ifdef FORCE_METHOD
973 if (gCompressionLevel == 2 && buf != (char*)NULL) { /* force stored block */
974#else
975 if (stored_len+4 <= opt_lenb && buf != (char*)NULL) {
976 /* 4: two words for the lengths */
977#endif
978 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
979 * Otherwise we can't have processed more than WSIZE input bytes since
980 * the last block flush, because compression would have been
981 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
982 * transform a block into a stored block.
983 */
984 R__send_bits(state,(STORED_BLOCK<<1)+eof, 3); /* send block type */
985 t_state->compressed_len = (t_state->compressed_len + 3 + 7) & ~7L;
986 t_state->compressed_len += (stored_len + 4) << 3;
987
988 R__copy_block(state, buf, (unsigned)stored_len, 1); /* with header */
989
990#ifdef FORCE_METHOD
991 } else if (gCompressionLevel == 3) { /* force static trees */
992#else
993 } else if (static_lenb == opt_lenb) {
994#endif
995 R__send_bits(state,(STATIC_TREES<<1)+eof, 3);
996 R__compress_block(state, t_state, (ct_data near *)t_state->static_ltree,
997 (ct_data near *)t_state->static_dtree );
998 t_state->compressed_len += 3 + t_state->static_len;
999 } else {
1000 R__send_bits(state,(DYN_TREES<<1)+eof, 3);
1001 R__send_all_trees(state, t_state, t_state->l_desc.max_code+1, t_state->d_desc.max_code+1, max_blindex+1);
1002 R__compress_block(state, t_state, (ct_data near *)t_state->dyn_ltree, (ct_data near *)t_state->dyn_dtree);
1003 t_state->compressed_len += 3 + t_state->opt_len;
1004 }
1005 Assert (t_state->compressed_len == t_state->R__bits_sent, "bad compressed size");
1006 R__init_block(t_state);
1007
1008 if (eof) {
1009#if defined(PGP) && !defined(MMAP)
1010 /* Wipe out sensitive data for pgp */
1011 /*
1012 *# ifdef DYN_ALLOC
1013 * extern uch *R__window;
1014 *# else
1015 * extern uch R__window[];
1016 *# endif
1017 */
1018 memset(R__window, 0, (unsigned)(2*WSIZE-1)); /* -1 needed if WSIZE=32K */
1019#else /* !PGP */
1020 Assert (input_len == R__isize, "bad input size");
1021#endif
1022 R__bi_windup(state);
1023 t_state->compressed_len += 7; /* align on byte boundary */
1024 }
1025 Tracev((stderr,"\ncomprlen %lu(%lu) ", t_state->compressed_len>>3,
1026 t_state->compressed_len-7*eof));
1027
1028 return t_state->compressed_len >> 3;
1029 }
1030
1031 /* ===========================================================================
1032 * Save the match info and tally the frequency counts. Return true if
1033 * the current block must be flushed.
1034 */
1035 int R__ct_tally (bits_internal_state *state, int dist, int lc)
1036 /* int dist; distance of matched string */
1037 /* int lc; match length-MIN_MATCH or unmatched char (if dist==0) */
1038 {
1039 tree_internal_state *t_state = state->t_state;
1040 t_state->l_buf[t_state->last_lit++] = (uch)lc;
1041 if (dist == 0) {
1042 /* lc is the unmatched char */
1043 t_state->dyn_ltree[lc].Freq++;
1044 } else {
1045 /* Here, lc is the match length - MIN_MATCH */
1046 dist--; /* dist = match distance - 1 */
1047 Assert((ush)dist < (ush)MAX_DIST &&
1048 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1049 (ush)d_code(dist) < (ush)D_CODES, "R__ct_tally: bad match");
1050
1051 t_state->dyn_ltree[t_state->length_code[lc]+LITERALS+1].Freq++;
1052 t_state->dyn_dtree[d_code(dist)].Freq++;
1053
1054 t_state->d_buf[t_state->last_dist++] = dist;
1055 t_state->flags |= t_state->flag_bit;
1056 }
1057 t_state->flag_bit <<= 1;
1058
1059 /* Output the flags if they fill a byte: */
1060 if ((t_state->last_lit & 7) == 0) {
1061 t_state->flag_buf[t_state->last_flags++] = t_state->flags;
1062 t_state->flags = 0, t_state->flag_bit = 1;
1063 }
1064 /* Try to guess if it is profitable to stop the current block here */
1065 if (gCompressionLevel > 2 && (t_state->last_lit & 0xfff) == 0) {
1066 /* Compute an upper bound for the compressed length */
1067 ulg out_length = (ulg)t_state->last_lit*8L;
1068 ulg in_length = (ulg)state->R__strstart-state->R__block_start;
1069 int dcode;
1070 for (dcode = 0; dcode < D_CODES; dcode++) {
1071 out_length += (ulg)t_state->dyn_dtree[dcode].Freq*(5L+extra_dbits[dcode]);
1072 }
1073 out_length >>= 3;
1074 Trace((stderr,"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
1075 t_state->last_lit, t_state->last_dist, in_length, out_length,
1076 100L - out_length*100L/in_length));
1077 if (t_state->last_dist < t_state->last_lit/2 && out_length < in_length/2) return 1;
1078 }
1079 return (t_state->last_lit == LIT_BUFSIZE-1 || t_state->last_dist == DIST_BUFSIZE);
1080 /* We avoid equality with LIT_BUFSIZE because of wraparound at 64K
1081 * on 16 bit machines and because stored blocks are restricted to
1082 * 64K-1 bytes.
1083 */
1084 }
1085
1086 /* ===========================================================================
1087 * Send the block data compressed using the given Huffman trees
1088 */
1090 /* ct_data near *ltree; literal tree */
1091 /* ct_data near *dtree; distance tree */
1092 {
1093 unsigned dist; /* distance of matched string */
1094 int lc; /* match length or unmatched char (if dist == 0) */
1095 unsigned lx = 0; /* running index in l_buf */
1096 unsigned dx = 0; /* running index in d_buf */
1097 unsigned fx = 0; /* running index in flag_buf */
1098 uch flag = 0; /* current flags */
1099 unsigned code; /* the code to send */
1100 int extra; /* number of extra bits to send */
1101
1102 if (t_state->last_lit != 0) do {
1103 if ((lx & 7) == 0) flag = t_state->flag_buf[fx++];
1104 lc = t_state->l_buf[lx++];
1105 if ((flag & 1) == 0) {
1106 send_code(lc, ltree); /* send a literal byte */
1107 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1108 } else {
1109 /* Here, lc is the match length - MIN_MATCH */
1110 code = t_state->length_code[lc];
1111 send_code(code+LITERALS+1, ltree); /* send the length code */
1112 extra = extra_lbits[code];
1113 if (extra != 0) {
1114 lc -= t_state->base_length[code];
1115 R__send_bits(state,lc, extra); /* send the extra length bits */
1116 }
1117 dist = t_state->d_buf[dx++];
1118 /* Here, dist is the match distance - 1 */
1119 code = d_code(dist);
1120 Assert (code < D_CODES, "bad d_code");
1121
1122 send_code(code, dtree); /* send the distance code */
1123 extra = extra_dbits[code];
1124 if (extra != 0) {
1125 dist -= t_state->base_dist[code];
1126 R__send_bits(state,dist, extra); /* send the extra distance bits */
1127 }
1128 } /* literal or match pair ? */
1129 flag >>= 1;
1130 } while (lx < t_state->last_lit);
1131
1132 send_code(END_BLOCK, ltree);
1133 }
1134
1135 /* ===========================================================================
1136 * Set the file type to ASCII or BINARY, using a crude approximation:
1137 * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
1138 * IN assertion: the fields freq of dyn_ltree are set and the total of all
1139 * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
1140 */
1142 {
1143 int n = 0;
1144 unsigned ascii_freq = 0;
1145 unsigned bin_freq = 0;
1146 while (n < 7) bin_freq += t_state->dyn_ltree[n++].Freq;
1147 while (n < 128) ascii_freq += t_state->dyn_ltree[n++].Freq;
1148 while (n < LITERALS) bin_freq += t_state->dyn_ltree[n++].Freq;
1149 *t_state->R__file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
1150#ifndef PGP
1151#if 0
1152 if (*t_state->R__file_type == BINARY && translate_eol) {
1153 warn("-l used on binary file", "");
1154 }
1155#endif
1156#endif
1157 }
unsigned R__bi_reverse(unsigned code, int len)
Definition Bits.c:181
int R__copy_block(bits_internal_state *state, char *buf, unsigned len, int header)
Definition Bits.c:236
int R__error(char *msg)
Definition Bits.c:125
int R__send_bits(bits_internal_state *state, int value, int length)
Definition Bits.c:151
int gCompressionLevel
Copyright (C) 1990-1993 Mark Adler, Richard B.
Definition Bits.c:77
int R__bi_windup(bits_internal_state *state)
Definition Bits.c:217
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
#define far
Definition Tailor.h:122
#define near
Definition Tailor.h:123
#define fcalloc(items, size)
Definition Tailor.h:127
#define OF(a)
Definition Tailor.h:87
#define local
Definition ZIP.h:55
#define Tracec(c, x)
Definition ZIP.h:88
int R__ct_init()
#define Tracecv(c, x)
Definition ZIP.h:89
#define Assert(cond, msg)
Definition ZIP.h:84
#define ASCII
Definition ZIP.h:63
#define Tracev(x)
Definition ZIP.h:86
#define MIN_MATCH
Definition ZIP.h:22
ulg R__flush_block()
#define MAX_MATCH
Definition ZIP.h:23
#define UNKNOWN
Definition ZIP.h:61
#define STORE
Definition ZIP.h:66
#define BINARY
Definition ZIP.h:62
int R__ct_tally()
#define MAX_DIST
Definition ZIP.h:39
#define NULL
Definition ZInflate.c:15
unsigned short ush
Definition ZInflate.c:225
#define WSIZE
Definition ZInflate.c:229
#define Trace(x)
Definition ZInflate.c:250
unsigned long ulg
Definition ZInflate.c:226
unsigned char uch
Definition ZInflate.c:224
static int R__build_bl_tree()
#define Code
Definition ZTrees.c:172
#define STATIC_TREES
Definition ZTrees.c:109
static int R__set_file_type()
#define DIST_BUFSIZE
Definition ZTrees.c:124
int R__tree_desc_init(tree_desc *tree_description, ct_data *dyn_tree, ct_data *static_tree, int *extra_bits, int extra_base, int elems, int max_length, int max_code)
Definition ZTrees.c:349
#define HEAP_SIZE
Definition ZTrees.c:176
#define END_BLOCK
Definition ZTrees.c:86
#define pqremove(tree, top)
Definition ZTrees.c:485
#define LIT_BUFSIZE
Definition ZTrees.c:120
static int R__gen_bitlen()
#define L_CODES
Definition ZTrees.c:89
#define REPZ_11_138
Definition ZTrees.c:152
#define REPZ_3_10
Definition ZTrees.c:149
static int extra_blbits[19]
Definition ZTrees.c:106
#define LITERALS
Definition ZTrees.c:83
#define DYN_TREES
Definition ZTrees.c:110
#define Len
Definition ZTrees.c:174
#define MAX_BITS
Definition ZTrees.c:74
#define d_code(dist)
Definition ZTrees.c:339
tree_internal_state * R__get_thread_tree_state()
Definition ZTrees.c:293
#define REP_3_6
Definition ZTrees.c:146
#define smaller(tree, n, m)
Definition ZTrees.c:496
static int R__gen_codes()
#define send_code(c, tree)
Definition ZTrees.c:330
#define D_CODES
Definition ZTrees.c:92
#define Freq
Definition ZTrees.c:171
#define LENGTH_CODES
Definition ZTrees.c:80
TTHREAD_TLS_DECLARE(int, tree_state_isInit)
#define MAX_BL_BITS
Definition ZTrees.c:77
#define BL_CODES
Definition ZTrees.c:95
#define STORED_BLOCK
Definition ZTrees.c:108
static int R__send_all_trees()
static int extra_dbits[30]
Definition ZTrees.c:103
static int R__scan_tree()
static int R__build_tree()
static int extra_lbits[29]
Definition ZTrees.c:100
static int R__send_tree()
#define SMALLEST
Definition ZTrees.c:477
static int R__pqdownheap()
uch bl_order[19]
Definition ZTrees.c:180
static int R__compress_block()
#define MAX(a, b)
Definition ZTrees.c:346
static int R__init_block()
subroutine node(ivo, nuserm, iposp)
Definition g2root.f:833
const Int_t n
Definition legend1.C:16
tree_internal_state * t_state
Definition Bits.h:175
unsigned R__strstart
Definition Bits.h:145
long R__block_start
Definition Bits.h:123
union ct_data::@147027034057035375272017203014232062050335167353 dl
ush len
Definition ZTrees.c:167
ush freq
Definition ZTrees.c:162
ush dad
Definition ZTrees.c:166
ush code
Definition ZTrees.c:163
union ct_data::@315157103136215207363327301301344204111273034170 fc
int max_length
Definition ZTrees.c:191
int elems
Definition ZTrees.c:190
ct_data * dyn_tree
Definition ZTrees.c:186
ct_data * static_tree
Definition ZTrees.c:187
int * extra_bits
Definition ZTrees.c:188
int max_code
Definition ZTrees.c:192
int extra_base
Definition ZTrees.c:189
uch dist_code[512]
Definition ZTrees.c:237
uch depth[2 *(256+1+29)+1]
Definition ZTrees.c:231
tree_desc bl_desc
Definition ZTrees.c:218
uch l_buf[0x8000]
Definition ZTrees.c:250
ush bl_count[15+1]
Definition ZTrees.c:221
tree_desc l_desc
Definition ZTrees.c:214
int base_dist[30]
Definition ZTrees.c:246
ct_data static_dtree[30]
Definition ZTrees.c:206
uch length_code[258 - 3+1]
Definition ZTrees.c:234
uch flag_buf[(0x8000/8)]
Definition ZTrees.c:257
ct_data dyn_dtree[2 *30+1]
Definition ZTrees.c:197
ct_data dyn_ltree[(2 *(256+1+29)+1)]
Definition ZTrees.c:196
int base_length[29]
Definition ZTrees.c:243
int heap[2 *(256+1+29)+1]
Definition ZTrees.c:224
unsigned last_lit
Definition ZTrees.c:262
ush d_buf[0x8000]
Definition ZTrees.c:251
unsigned last_flags
Definition ZTrees.c:264
unsigned last_dist
Definition ZTrees.c:263
tree_desc d_desc
Definition ZTrees.c:216
ct_data bl_tree[2 *19+1]
Definition ZTrees.c:211
ct_data static_ltree[(256+1+29)+2]
Definition ZTrees.c:199
TMarker m
Definition textangle.C:8
TTree * tree