MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / CodeTree

Method CodeTree

src/cryptlib/ztrees.cpp:106–189  ·  view source on GitHub ↗

Allocate the match buffer and initialize the various tables. */

Source from the content-addressed store, hash-verified

104
105/* Allocate the match buffer and initialize the various tables. */
106CodeTree::CodeTree(int deflate_level, BufferedTransformation &outQ)
107 : BitOutput(outQ),
108 deflate_level(deflate_level),
109 dyn_ltree(HEAP_SIZE), dyn_dtree(2*D_CODES+1),
110 bl_tree(2*BL_CODES+1),
111 bl_count(MAX_BITS+1),
112 l_desc(dyn_ltree, static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS, 0),
113 d_desc(dyn_dtree, static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0),
114 bl_desc(bl_tree, (ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS, 0),
115 heap(2*L_CODES+1),
116 depth(2*L_CODES+1),
117 length_code(MAX_MATCH-MIN_MATCH+1),
118 dist_code(512),
119 base_length(LENGTH_CODES),
120 base_dist(D_CODES),
121 l_buf(LIT_BUFSIZE),
122 d_buf(DIST_BUFSIZE),
123 flag_buf(LIT_BUFSIZE/8)
124{
125
126 unsigned int n; /* iterates over tree elements */
127 unsigned int bits; /* bit counter */
128 unsigned int length; /* length value */
129 register unsigned int code; /* code value */
130 unsigned int dist; /* distance index */
131
132 compressed_len = input_len = 0L;
133
134 /* Initialize the mapping length (0..255) -> length code (0..28) */
135 length = 0;
136 for (code=0; code < LENGTH_CODES-1; code++) {
137 base_length[code] = length;
138 for (n=0; n < (1U<<extra_lbits[code]); n++) {
139 length_code[length++] = (byte)code;
140 }
141 }
142 assert (length == 256);
143 /* Note that the length 255 (match length 258) can be represented
144 in two different ways: code 284 + 5 bits or code 285, so we
145 overwrite length_code[255] to use the best encoding: */
146 length_code[length-1] = (byte)code;
147
148 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
149 dist = 0;
150 for (code=0 ; code < 16; code++) {
151 base_dist[code] = dist;
152 for (n=0; n < (1U<<extra_dbits[code]); n++) {
153 dist_code[dist++] = (byte)code;
154 }
155 }
156 assert (dist == 256);
157 dist >>= 7; /* from now on, all distances are divided by 128 */
158 for (; code < D_CODES; code++) {
159 base_dist[code] = dist << 7;
160 for (n=0; n < (1U<<(extra_dbits[code]-7)); n++) {
161 dist_code[256 + dist++] = (byte)code;
162 }
163 }

Callers

nothing calls this directly

Calls 1

reverseFunction · 0.85

Tested by

no test coverage detected