-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpa106cslzc.h
200 lines (150 loc) · 6.38 KB
/
hpa106cslzc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*@(#)cslzc.h 20.8 SAP 97/11/11
========== licence begin GPL
Copyright (c) 1992-2005 SAP AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
========== licence end
*/
/*
* SAP AG Walldorf
* Systeme, Anwendungen und Produkte in der Datenverarbeitung
*
*/
/*--------------------------------------------------------------------*/
/* Internal Header File */
/* */
/* Definitions for LZC Algorithm */
/* */
/*--------------------------------------------------------------------*/
#ifndef CSLZC_INCL /* cannot be included twice .................*/
#define CSLZC_INCL
/*--------------------------------------------------------------------*/
/* Macros (internal) */
/*--------------------------------------------------------------------*/
/* for 16 Bit OS ................*/
#if defined ( OS_16 )
#define LARGE_ARRAY far
#else
#define LARGE_ARRAY
#endif
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef CS_BITS
#define CS_BITS 13 /* max. number of bits (default) ......*/
#endif
/* If a new version is added, change CS_VERSION
*/
#define CS_VERSION (BYTE_TYP) 1
#define CS_ALGORITHM (BYTE_TYP) 1 /* never change this ..........*/
#define FIRST 257 /* first free entry ...................*/
#define CLEAR 256 /* table clear output code ............*/
/* ratio check interval ...............*/
#define CHECK_GAP 4096 /* 10000 */
/* Defines for 8. byte of header .....................................*/
#define BIT_MASK 0x1f
#define BLOCK_MASK 0x80
/* Masks 0x40 and 0x20 are free. */
#define INIT_CS_BITS 9 /* initial number of bits/code ........*/
#define MAX_CS_BITS 16 /* max. number of bits/code ...........*/
#if CS_BITS <= INIT_CS_BITS /* CS_BITS at least INIT_CS_BITS + 1 ..*/
#undef CS_BITS
#define CS_BITS (INIT_CS_BITS + 1)
#endif
#if CS_BITS > MAX_CS_BITS /* CS_BITS at most MAX_CS_BITS ........*/
#undef CS_BITS
#define CS_BITS MAX_CS_BITS
#endif
/*--------------------------------------------------------------------*/
/* TYPES (depending on CS_BITS) */
/*--------------------------------------------------------------------*/
typedef SAP_BYTE BYTE_TYP;
#if CS_BITS > 15
typedef long int CODE_INT;
#else
typedef int CODE_INT;
#endif
typedef long int COUNT_INT;
typedef unsigned short CODE_ENTRY;
/*--------------------------------------------------------------------*/
/* Size of the hash table depending on CS_BITS .......................*/
/*--------------------------------------------------------------------*/
#if CS_BITS == 16
#define HSIZE 69001U /* 95% occupancy 65536/69001 .........*/
#define CSIZE 69001U
#endif
#if CS_BITS == 15
#define HSIZE 35023U /* 94% occupancy 32768/35023 .........*/
#define CSIZE 69001U
#endif
#if CS_BITS == 14
#define HSIZE 18013U /* 91% occupancy 16384/18013 .........*/
#define CSIZE 35023U
#endif
#if CS_BITS == 13
#define HSIZE 9001U /* 91% occupancy 8192/9001 .........*/
#define CSIZE 18013U
#endif
#if CS_BITS <= 12
#define HSIZE 5003U /* 80% occupancy 4096/5003 .........*/
#define CSIZE 9001U
#endif
/*--------------------------------------------------------------------*/
/* Access Macros for code and hash tables ............................*/
/*--------------------------------------------------------------------*/
#define MAXCODE(n_bits) (((CODE_INT) 1 << (n_bits)) - 1)
#define HTABOF(i) csc.htab[i]
#define CODETABOF(i) csc.codetab[i]
/*
* To save much memory, we overlay the table used by CsCompr () with
* those used by CsDecompr (). The TAB_PREFIX table is the same size
* and type as the codetab. The TAB_SUFFIX table needs 2^BITS
* characters. We get this from the beginning of htab.
* The output stack uses the rest of htab, and contains characters.
* There is plenty of room for any possible stack (stack used to
* be 8000 characters).
*/
#define TAB_PREFIXOF(i) csc.Prefixtab[i]
#define TAB_SUFFIXOF(i) csc.Suffixtab[i]
/* following definition gives a compiler warning on HP 64 bit (2001-05-15)
Maybe this will work again some time later.
#define DE_STACK &TAB_SUFFIXOF((CODE_INT)1<<(CS_BITS+1))
Definition beneath works on HP, too, but requires an extra global var.
*/
extern CODE_INT DE_STACK_OFFSET;
#define DE_STACK &TAB_SUFFIXOF(DE_STACK_OFFSET)
/* Clear Hash Table ..................................................*/
#define CL_HASH(size) \
memset (csc.htab, 0xff, (size) * sizeof (COUNT_INT));
#ifdef USE_MEMCPY /* use memcpy to transfer bytes ..........*/
#define BYTES_OUT(dst,src,len) \
memcpy (dst,src,len); dst += len;
#define BYTES_IN(to,from,len) \
memcpy (to,from,len); from += len;
#else /* native copy ...........................*/
#define BYTES_OUT(dst,src,len) \
{ \
register int i_i = len; \
register BYTE_TYP *bufp = src; \
while (i_i-- > 0) *dst++ = *bufp++; \
}
#define BYTES_IN(to,from,len) \
{ \
register int i_i = len; \
register BYTE_TYP *bufp = to; \
while (i_i-- > 0) *bufp++ = *from++; \
}
#endif /* USE_MEMCPY */
#endif /* CSLZC_INCL */