Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
Bits.h
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9/**
10 * Bits.h is a collection of function definitions for the historic compression
11 * algorithm used by ROOT. This appears to have been a modified ZLIB-like
12 * algorithm.
13 *
14 * As best as we can tell, this has not been used in 20+ years.
15 */
16
17#include "ZIP.h"
18
19/* This following used to be declared (as globals) in ZDeflate.h */
20
21/**
22 * Size of internal hash table.
23 *
24 * Previously controlled by various macros which no longer exist.
25 *
26 */
27#define HASH_BITS 15
28#define HASH_SIZE (unsigned)(1<<HASH_BITS)
29
30#if defined(BIG_MEM) || defined(MMAP)
31typedef unsigned Pos; /* must be at least 32 bits */
32#else
33typedef ush Pos;
34#endif
35typedef unsigned IPos;
36/* A Pos is an index in the character window. We use short instead of int to
37 * save space in the various tables. IPos is used only for parameter passing.
38 */
39
40/* end of ZDeflate.h section */
41
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
48 unsigned short bi_buf;
49 /* Output buffer. bits are inserted starting at the bottom (least significant
50 * bits).
51 */
52
54 /* Number of valid bits in bi_buf. All bits above the last valid bit
55 * are always zero.
56 */
57
58 const char *in_buf;
59 char *out_buf;
60 /* Current input and output buffers. in_buf is used only for in-memory
61 * compression.
62 */
63
65 /* Current offset in input and output buffers. in_offset is used only for
66 * in-memory compression. On 16 bit machiens, the buffer is limited to 64K.
67 */
68
69 unsigned in_size, out_size;
70 /* Size of current input and output buffers */
71
72 /* On some platform (MacOS) marking this thread local does not work,
73 however in our use this is a constant, so we do not really need to make it
74 thread local */
75 /* __thread */
76 /* not used?
77 int (*R__read_buf) OF((char *buf, unsigned size)) = R__mem_read;
78 */
79 /* Current input function. Set to R__mem_read for in-memory compression */
80
81#ifdef DEBUG
82 ulg R__bits_sent; /* bit length of the compressed data */
83#endif
84
86
87 /* The following used to be declared (as globals) in ZDeflate.h */
88
89 /* ===========================================================================
90 * Local data used by the "longest match" routines.
91 */
92
93#ifndef DYN_ALLOC
95 /* Sliding window. Input bytes are read into the second half of the window,
96 * and move to the first half later to keep a dictionary of at least WSIZE
97 * bytes. With this organization, matches are limited to a distance of
98 * WSIZE-MAX_MATCH bytes, but this ensures that IO is always
99 * performed with a length multiple of the block size. Also, it limits
100 * the window size to 64K, which is quite useful on MSDOS.
101 * To do: limit the window size to WSIZE+BSZ if SMALL_MEM (the code would
102 * be less efficient since the data would have to be copied WSIZE/BSZ times)
103 */
105 /* Link to older string with same hash index. To limit the size of this
106 * array to 64K, this link is maintained only for the last 32K strings.
107 * An index in this array is thus a window index modulo 32K.
108 */
110 /* Heads of the hash chains or NIL. If your compiler thinks that
111 * HASH_SIZE is a dynamic value, recompile with -DDYN_ALLOC.
112 */
113#else
114 uch * near R__window ; /* = NULL; */
115 Pos * near R__prev ; /* = NULL; */
116 Pos * near R__head;
117#endif
119 /* window size, 2*WSIZE except for MMAP or BIG_MEM, where it is the
120 * input file length plus MIN_LOOKAHEAD.
121 */
122
124 /* window position at the beginning of the current output block. Gets
125 * negative when the window is moved backwards.
126 */
127
128 /* local */ int sliding;
129 /* Set to false when the input file is already in memory */
130
131 /* local */ unsigned ins_h; /* hash index of string to be inserted */
132
133#define H_SHIFT ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH)
134 /* Number of bits by which ins_h and del_h must be shifted at each
135 * input step. It must be such that after MIN_MATCH steps, the oldest
136 * byte no longer takes part in the hash key, that is:
137 * H_SHIFT * MIN_MATCH >= HASH_BITS
138 */
139
140 unsigned int near R__prev_length;
141 /* Length of the best match at previous step. Matches not greater than this
142 * are discarded. This is used in the lazy match evaluation.
143 */
144
145 unsigned near R__strstart; /* start of string to insert */
146 unsigned near R__match_start; /* start of matching string */
147 /* local */ int eofile; /* flag set at end of input file */
148 /* local */ unsigned lookahead; /* number of valid bytes ahead in window */
149
151 /* To speed up deflation, hash chains are never searched beyond this length.
152 * A higher limit improves compression ratio but degrades the speed.
153 */
154
155 /* local */ unsigned int max_lazy_match;
156 /* Attempt to find a better match only when the current match is strictly
157 * smaller than this value. This mechanism is used only for compression
158 * levels >= 4.
159 */
160#define max_insert_length state->max_lazy_match
161 /* Insert new strings in the hash table only if the match length
162 * is not greater than this length. This saves time but degrades compression.
163 * max_insert_length is used only for compression levels <= 3.
164 */
165
167 /* Use a faster search when the previous match is longer than this */
168
169#ifdef FULL_SEARCH
170# define R__nice_match MAX_MATCH
171#else
172 int near R__nice_match; /* Stop searching when current match exceeds this */
173#endif
174
176 /* Pointer to the ZTree internal state, this will be thread local */
177};
178
179/* ===========================================================================
180 * Initialize the bit string routines.
181 */
183
184/* ===========================================================================
185 * Send a value on a given number of bits.
186 * IN assertion: length <= 16 and value fits in length bits.
187 */
188 /* int value; value to send */
189 /* int length; number of bits */
190void R__send_bits(bits_internal_state *state, int value, int length);
191
192
193/* ===========================================================================
194 * Reverse the first len bits of a code, using straightforward code (a faster
195 * method would use a table)
196 * IN assertion: 1 <= len <= 15
197 */
198 /* unsigned code; the value to invert */
199 /* int len; its bit length */
200unsigned R__bi_reverse(unsigned code, int len);
201
202
203/* ===========================================================================
204 * Write out any remaining bits in an incomplete byte.
205 */
207
208
209/* ===========================================================================
210 * Copy a stored block to the zip file, storing first the length and its
211 * one's complement if requested.
212 */
213 /* char far *buf; the input data */
214 /* unsigned len; its length */
215 /* int header; true if block header must be written */
216void R__copy_block(bits_internal_state *state, char far *buf, unsigned len, int header);
217
218
219/* ===========================================================================
220 * In-memory read function. As opposed to file_read(), this function
221 * does not perform end-of-line translation, and does not update the
222 * crc and input size.
223 * Note that the size of the entire input buffer is an unsigned long,
224 * but the size used in R__mem_read() is only an unsigned int. This makes a
225 * difference on 16 bit machines. R__mem_read() may be called several
226 * times for an in-memory compression.
227 */
228int R__mem_read OF((bits_internal_state *state, char *b, unsigned bsize));
229
230/* ===========================================================================
231 * In-memory compression. This version can be used only if the entire input
232 * fits in one memory buffer. The compression is then done in a single
233 * call of R__memcompress(). (An extension to allow repeated calls would be
234 * possible but is not needed here.)
235 * The first two bytes of the compressed output are set to a short with the
236 * method used (DEFLATE or STORE). The following four bytes contain the CRC.
237 * The values are stored in little-endian order on all machines.
238 * This function returns the byte size of the compressed output, including
239 * the first six bytes (method and crc).
240 */
241 /* char *tgt, *src; target and source buffers */
242 /* ulg tgtsize, srcsize; target and source sizes */
243ulg R__memcompress(char *tgt, ulg tgtsize, const char *src, ulg srcsize);
244
245/**
246 * Decompress a deflated entry.
247 */
248int R__Inflate(const uch **ibufptr, long *ibufcnt, uch **obufptr, long *obufcnt);
249
250#ifdef __cplusplus
251} // extern "C"
252#endif
int R__mem_read(bits_internal_state *state, char *b, unsigned bsize)
Definition Bits.c:353
int R__bi_init(bits_internal_state *state)
Definition Bits.c:134
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
ush Pos
Definition Bits.h:33
#define HASH_SIZE
Definition Bits.h:28
int R__send_bits(bits_internal_state *state, int value, int length)
Definition Bits.c:151
unsigned IPos
Definition Bits.h:35
ulg R__memcompress(char *tgt, ulg tgtsize, char *src, ulg srcsize)
Definition Bits.c:294
int R__bi_windup(bits_internal_state *state)
Definition Bits.c:217
#define b(i)
Definition RSha256.hxx:100
#define far
Definition Tailor.h:122
#define near
Definition Tailor.h:123
#define OF(a)
Definition Tailor.h:87
unsigned short ush
Definition ZInflate.c:225
#define WSIZE
Definition ZInflate.c:229
int R__Inflate()
unsigned long ulg
Definition ZInflate.c:226
unsigned char uch
Definition ZInflate.c:224
unsigned out_size
Definition Bits.h:69
unsigned int max_lazy_match
Definition Bits.h:155
unsigned R__max_chain_length
Definition Bits.h:150
tree_internal_state * t_state
Definition Bits.h:175
uch R__window[2L *((unsigned) 32768)]
Definition Bits.h:94
unsigned out_offset
Definition Bits.h:64
unsigned in_size
Definition Bits.h:69
unsigned lookahead
Definition Bits.h:148
unsigned int R__prev_length
Definition Bits.h:140
unsigned in_offset
Definition Bits.h:64
unsigned ins_h
Definition Bits.h:131
unsigned short bi_buf
Definition Bits.h:48
unsigned R__strstart
Definition Bits.h:145
unsigned R__match_start
Definition Bits.h:146
unsigned R__good_match
Definition Bits.h:166
Pos R__prev[((unsigned) 32768)]
Definition Bits.h:104
long R__block_start
Definition Bits.h:123
Pos R__head[(unsigned)(1<< 15)]
Definition Bits.h:109
char * in_buf
Definition Bits.h:58
char * out_buf
Definition Bits.h:59