source: trunk/indexers/mg/lib/bitio_gen.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: 2.9 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 3745 2003-02-20 21:20:24Z mdewsnip $
21 *
22 **************************************************************************/
23
24static char *RCSID = "$Id: bitio_gen.c 3745 2003-02-20 21:20:24Z mdewsnip $";
25
26#include "sysfuncs.h"
27#include "bitio_m.h"
28
29
30
31
32int fprintf (FILE *, const char *,...);
33
34unsigned long
35BIO_Unary_Length (unsigned long val)
36{
37 register unsigned long num;
38 UNARY_LENGTH (val, num);
39 return (num);
40}
41
42
43unsigned long
44BIO_Binary_Length (unsigned long val, unsigned long b)
45{
46 register unsigned long num;
47 BINARY_LENGTH (val, b, num);
48 return (num);
49}
50
51
52unsigned long
53BIO_Gamma_Length (unsigned long val)
54{
55 register unsigned long num;
56 GAMMA_LENGTH (val, num);
57 return (num);
58}
59
60
61unsigned long
62BIO_Delta_Length (unsigned long val)
63{
64 register unsigned long num;
65 DELTA_LENGTH (val, num);
66 return (num);
67}
68
69
70unsigned long
71BIO_Elias_Length (unsigned long val, unsigned long b, double s)
72{
73 register unsigned long num;
74 ELIAS_LENGTH (val, b, s, num);
75 return (num);
76}
77
78unsigned long
79BIO_Bblock_Length (unsigned long val, unsigned long b)
80{
81 register unsigned long num;
82 BBLOCK_LENGTH (val, b, num);
83 return (num);
84}
85
86
87int
88BIO_Bblock_Init (int N, int p)
89{
90 int b;
91 b = (int) (0.5 + 0.6931471 * N / p);
92 return (b ? b : 1);
93}
94
95
96int
97BIO_Bblock_Init_W (int N, int p)
98{
99 int logb;
100 FLOORLOG_2 ((N - p) / p, logb);
101 return (logb < 0 ? 1 : (1 << logb));
102}
103
104int
105BIO_Bblock_Bound_b (int N, int p, int b)
106{
107 int clogb;
108 CEILLOG_2 (b, clogb);
109 return (p * (1 + clogb) + (N - p * ((1 << clogb) - b + 1)) / b);
110}
111
112int
113BIO_Bblock_Bound (int N, int p)
114{
115 int b;
116 b = BIO_Bblock_Init_W (N, p);
117 return (BIO_Bblock_Bound_b (N, p, b));
118}
119
120
121/* adjustment is a hack to overcome inaccuracies in floating point,
122 where (int)(ln4/ln2) can equal 1, not 2. */
123/* copied from mg-1.3f, 17-09-01 kjm18 */
124int
125BIO_Gamma_Bound (int N, int p)
126{
127 /* return ((int) (p * (2 * log2 ((double) N / p) + 1))); */
128 return ((int) (p * (2 * log2 (((double) N * 1.0001) / p) + 1)));
129}
130
131int
132floorlog_2 (int b)
133{
134 int logb;
135 FLOORLOG_2 (b, logb);
136 return logb;
137}
138
139int
140ceillog_2 (int b)
141{
142 int logb;
143 CEILLOG_2 (b, logb);
144 return logb;
145}
Note: See TracBrowser for help on using the repository browser.