source: trunk/gsdl3/src/packages/mg/lib/bitio_random.c@ 3745

Last change on this file since 3745 was 3745, checked in by mdewsnip, 21 years ago

Addition of MG package for search and retrieval

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