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

Last change on this file since 1153 was 439, checked in by sjboddie, 25 years ago

renamed mg-1.3d directory mg

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