source: trunk/gsdl/packages/mg/lib/bitio_gen.c@ 3001

Last change on this file since 3001 was 3001, checked in by jrm21, 22 years ago

replaced a comment with /* */, as most c compilers won't like it.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/**************************************************************************
2 *
3 * bitio_gen.c -- General supoport routines for bitio
4 * Copyright (C) 1994 Neil Sharman and Alistair Moffat
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_gen.c 3001 2002-02-26 21:48:15Z jrm21 $
21 *
22 **************************************************************************/
23
24/*
25 $Log$
26 Revision 1.3 2002/02/26 21:48:15 jrm21
27 replaced a // comment with /* */, as most c compilers won't like it.
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:42 sjboddie
34 renamed mg-1.3d directory mg
35
36 Revision 1.1 1998/11/17 09:31:40 rjmcnab
37 *** empty log message ***
38
39 * Revision 1.1 1994/08/22 00:24:38 tes
40 * Initial placement under CVS.
41 *
42 */
43
44static char *RCSID = "$Id: bitio_gen.c 3001 2002-02-26 21:48:15Z jrm21 $";
45
46#include "sysfuncs.h"
47#include "bitio_m.h"
48
49
50
51
52int fprintf (FILE *, const char *,...);
53
54unsigned long
55BIO_Unary_Length (unsigned long val)
56{
57 register unsigned long num;
58 UNARY_LENGTH (val, num);
59 return (num);
60}
61
62
63unsigned long
64BIO_Binary_Length (unsigned long val, unsigned long b)
65{
66 register unsigned long num;
67 BINARY_LENGTH (val, b, num);
68 return (num);
69}
70
71
72unsigned long
73BIO_Gamma_Length (unsigned long val)
74{
75 register unsigned long num;
76 GAMMA_LENGTH (val, num);
77 return (num);
78}
79
80
81unsigned long
82BIO_Delta_Length (unsigned long val)
83{
84 register unsigned long num;
85 DELTA_LENGTH (val, num);
86 return (num);
87}
88
89
90unsigned long
91BIO_Elias_Length (unsigned long val, unsigned long b, double s)
92{
93 register unsigned long num;
94 ELIAS_LENGTH (val, b, s, num);
95 return (num);
96}
97
98unsigned long
99BIO_Bblock_Length (unsigned long val, unsigned long b)
100{
101 register unsigned long num;
102 BBLOCK_LENGTH (val, b, num);
103 return (num);
104}
105
106
107int
108BIO_Bblock_Init (int N, int p)
109{
110 int b;
111 b = (int) (0.5 + 0.6931471 * N / p);
112 return (b ? b : 1);
113}
114
115
116int
117BIO_Bblock_Init_W (int N, int p)
118{
119 int logb;
120 FLOORLOG_2 ((N - p) / p, logb);
121 return (logb < 0 ? 1 : (1 << logb));
122}
123
124int
125BIO_Bblock_Bound_b (int N, int p, int b)
126{
127 int clogb;
128 CEILLOG_2 (b, clogb);
129 return (p * (1 + clogb) + (N - p * ((1 << clogb) - b + 1)) / b);
130}
131
132int
133BIO_Bblock_Bound (int N, int p)
134{
135 int b;
136 b = BIO_Bblock_Init_W (N, p);
137 return (BIO_Bblock_Bound_b (N, p, b));
138}
139
140
141/* adjustment is a hack to overcome inaccuracies in floating point,
142 where (int)(ln4/ln2) can equal 1, not 2. */
143/* copied from mg-1.3f, 17-09-01 kjm18 */
144int
145BIO_Gamma_Bound (int N, int p)
146{
147 /* return ((int) (p * (2 * log2 ((double) N / p) + 1))); */
148 return ((int) (p * (2 * log2 (((double) N * 1.0001) / p) + 1)));
149}
150
151int
152floorlog_2 (int b)
153{
154 int logb;
155 FLOORLOG_2 (b, logb);
156 return logb;
157}
158
159int
160ceillog_2 (int b)
161{
162 int logb;
163 CEILLOG_2 (b, logb);
164 return logb;
165}
Note: See TracBrowser for help on using the repository browser.