source: trunk/gsdl/packages/mg/lib/bitio_random.c@ 10853

Last change on this file since 10853 was 2741, checked in by kjm18, 23 years ago

updated mg to be in line with version mg-1.3f. Now uses long long for
some variables to enable indexing of very large collections.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/*************************************************************************
2 *
3 * bitio_random.c -- Functions for bitio to a file (random access)
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id: bitio_random.c 2741 2001-09-20 02:31:59Z kjm18 $
21 *
22 **************************************************************************/
23
24/*
25 $Log$
26 Revision 1.2 2001/09/21 12:45:03 kjm18
27 updated mg to be in line with version mg-1.3f. Now uses long long for
28 some variables to enable indexing of very large collections.
29
30 Revision 1.1 1999/08/10 21:16:46 sjboddie
31 renamed mg-1.3d directory mg
32
33 Revision 1.1 1998/11/17 09:31:50 rjmcnab
34 *** empty log message ***
35
36 * Revision 1.1 1994/08/22 00:24:40 tes
37 * Initial placement under CVS.
38 *
39 */
40
41static char *RCSID = "$Id: bitio_random.c 2741 2001-09-20 02:31:59Z kjm18 $";
42
43
44
45#include "sysfuncs.h"
46#include "memlib.h"
47
48#include "longlong.h"
49
50#include "bitio_m_random.h"
51#include "bitio_m.h"
52
53
54void
55BIO_Random_Start (FILE * f, unsigned long len,
56 random_bitio_state * bs)
57{
58 ENCODE_START (f, len)
59 ENCODE_PAUSE (*bs)
60}
61
62void
63BIO_Random_Done (random_bitio_state * bs)
64{
65 ENCODE_CONTINUE (*bs)
66 ENCODE_DONE
67}
68
69void
70BIO_Random_Encode_Bit (int bit, random_bitio_state * bs)
71{
72 ENCODE_CONTINUE (*bs)
73 ENCODE_BIT (bit);
74 ENCODE_PAUSE (*bs)
75}
76
77int
78BIO_Random_Decode_Bit (random_bitio_state * bs)
79{
80 register int val;
81 DECODE_CONTINUE (*bs)
82 val = DECODE_BIT;
83 DECODE_PAUSE (*bs)
84 return (val);
85}
86
87
88void
89BIO_Random_Unary_Encode (unsigned long val, random_bitio_state * bs,
90 unsigned long *bits)
91{
92 ENCODE_CONTINUE (*bs)
93 if (bits)
94 UNARY_ENCODE_L (val, *bits);
95 else
96 UNARY_ENCODE (val);
97 ENCODE_PAUSE (*bs)
98}
99
100
101unsigned long
102BIO_Random_Unary_Decode (random_bitio_state * bs,
103 unsigned long *bits)
104{
105 register unsigned long val;
106 DECODE_CONTINUE (*bs)
107 if (bits)
108 UNARY_DECODE_L (val, *bits);
109 else
110 UNARY_DECODE (val);
111 DECODE_PAUSE (*bs)
112 return (val);
113}
114
115
116
117
118
119
120
121void
122BIO_Random_Binary_Encode (unsigned long val, unsigned long b,
123 random_bitio_state * bs, unsigned long *bits)
124{
125 ENCODE_CONTINUE (*bs)
126 if (bits)
127 BINARY_ENCODE_L (val, b, *bits);
128 else
129 BINARY_ENCODE (val, b);
130 ENCODE_PAUSE (*bs)
131}
132
133
134unsigned long
135BIO_Random_Binary_Decode (unsigned long b,
136 random_bitio_state * bs,
137 unsigned long *bits)
138{
139 register unsigned long val;
140 DECODE_CONTINUE (*bs)
141 if (bits)
142 BINARY_DECODE_L (val, b, *bits);
143 else
144 BINARY_DECODE (val, b);
145 DECODE_PAUSE (*bs)
146 return (val);
147}
148
149
150
151
152
153
154
155void
156BIO_Random_Gamma_Encode (unsigned long val, random_bitio_state * bs,
157 unsigned long *bits)
158{
159 ENCODE_CONTINUE (*bs)
160 if (bits)
161 GAMMA_ENCODE_L (val, *bits);
162 else
163 GAMMA_ENCODE (val);
164 ENCODE_PAUSE (*bs)
165}
166
167
168unsigned long
169BIO_Random_Gamma_Decode (random_bitio_state * bs,
170 unsigned long *bits)
171{
172 register unsigned long val;
173 DECODE_CONTINUE (*bs)
174 if (bits)
175 GAMMA_DECODE_L (val, *bits);
176 else
177 GAMMA_DECODE (val);
178 DECODE_PAUSE (*bs)
179 return (val);
180}
181
182
183
184
185void
186BIO_Random_Delta_Encode (unsigned long val, random_bitio_state * bs,
187 unsigned long *bits)
188{
189 ENCODE_CONTINUE (*bs)
190 if (bits)
191 DELTA_ENCODE_L (val, *bits);
192 else
193 DELTA_ENCODE (val);
194 ENCODE_PAUSE (*bs)
195}
196
197
198unsigned long
199BIO_Random_Delta_Decode (random_bitio_state * bs,
200 unsigned long *bits)
201{
202 register unsigned long val;
203 DECODE_CONTINUE (*bs)
204 if (bits)
205 DELTA_DECODE_L (val, *bits);
206 else
207 DELTA_DECODE (val);
208 DECODE_PAUSE (*bs)
209 return (val);
210}
211
212void
213BIO_Random_Elias_Encode (unsigned long val, unsigned long b, double s,
214 random_bitio_state * bs, unsigned long *bits)
215{
216 ENCODE_CONTINUE (*bs)
217 if (bits)
218 ELIAS_ENCODE_L (val, b, s, *bits);
219 else
220 ELIAS_ENCODE (val, b, s);
221 ENCODE_PAUSE (*bs)
222}
223
224
225unsigned long
226BIO_Random_Elias_Decode (unsigned long b, double s,
227 random_bitio_state * bs,
228 unsigned long *bits)
229{
230 register unsigned long val;
231 DECODE_CONTINUE (*bs)
232 if (bits)
233 ELIAS_DECODE_L (val, b, s, *bits);
234 else
235 ELIAS_DECODE (val, b, s);
236 DECODE_PAUSE (*bs)
237 return (val);
238}
239
240void
241BIO_Random_Bblock_Encode (unsigned long val, unsigned long b,
242 random_bitio_state * bs, unsigned long *bits)
243{
244 ENCODE_CONTINUE (*bs)
245 if (bits)
246 BBLOCK_ENCODE_L (val, b, *bits);
247 else
248 BBLOCK_ENCODE (val, b);
249 ENCODE_PAUSE (*bs)
250}
251
252
253unsigned long
254BIO_Random_Bblock_Decode (unsigned long b,
255 random_bitio_state * bs,
256 unsigned long *bits)
257{
258 register unsigned long val;
259 DECODE_CONTINUE (*bs)
260 if (bits)
261 BBLOCK_DECODE_L (val, b, *bits);
262 else
263 BBLOCK_DECODE (val, b);
264 DECODE_PAUSE (*bs)
265 return (val);
266}
267
268void
269BIO_Random_Seek (unsigned long pos, random_bitio_state * bs)
270{
271 ENCODE_CONTINUE (*bs)
272 ENCODE_SEEK (pos);
273 ENCODE_PAUSE (*bs)
274}
275void
276BIO_Random_Flush (random_bitio_state * bs)
277{
278 ENCODE_CONTINUE (*bs)
279 ENCODE_FLUSH;
280 ENCODE_PAUSE (*bs)
281}
282
283unsigned long
284BIO_Random_Tell (random_bitio_state * bs)
285{
286 register unsigned long t;
287 ENCODE_CONTINUE (*bs)
288 t = ENCODE_TELL;
289 ENCODE_PAUSE (*bs)
290 return (t);
291}
292
293#ifdef USE_LONG_LONG
294
295void
296BIO_Random_Seek_LL (mg_ullong pos, random_bitio_state * bs)
297{
298 ENCODE_CONTINUE(*bs)
299
300 if ((((pos) >> 3) >= (mg_ullong)__base) &&
301 ((((pos)+7) >> 3) < (mg_ullong)(__base + __len)))
302 {
303 __pos = (long)((pos) - (mg_ullong)(__base << 3));
304 }
305 else
306 {
307 ENCODE_FLUSH;
308 __base = (long)(((pos) >> (__sft+3)) << __sft);
309
310 fseek(__file,__base,0);
311 fread(__buf,1,__len,__file);
312 __pos = (long)((pos) & ((8 << __sft)-1));
313 }
314
315 ENCODE_PAUSE(*bs)
316}
317
318mg_ullong
319BIO_Random_Tell_LL (random_bitio_state * bs)
320{
321 mg_ullong t;
322 ENCODE_CONTINUE(*bs)
323 t = (((mg_ullong)__base) << 3ull) + __pos;
324 ENCODE_PAUSE(*bs)
325 return(t);
326}
327
328#endif
Note: See TracBrowser for help on using the repository browser.