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

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