source: trunk/gsdl/src/mgpp/lib/bitio_gen.cpp@ 855

Last change on this file since 855 was 855, checked in by sjboddie, 24 years ago

Rodgers new C++ mg

  • 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.cpp 855 2000-01-14 02:17:52Z sjboddie $
21 *
22 **************************************************************************/
23
24/*
25 $Log$
26 Revision 1.1 2000/01/14 02:16:58 sjboddie
27 Rodgers new C++ mg
28
29 Revision 1.1 1999/10/11 02:54:54 cs025
30 Base install of MG-PP
31
32 Revision 1.1 1999/08/10 21:16:42 sjboddie
33 renamed mg-1.3d directory mg
34
35 Revision 1.1 1998/11/17 09:31:40 rjmcnab
36 *** empty log message ***
37
38 * Revision 1.1 1994/08/22 00:24:38 tes
39 * Initial placement under CVS.
40 *
41 */
42
43static char *RCSID = "$Id: bitio_gen.cpp 855 2000-01-14 02:17:52Z sjboddie $";
44
45#include "sysfuncs.h"
46#include "bitio_m_abstract.h"
47
48
49
50
51int fprintf (FILE *, const char *,...);
52
53unsigned long
54BIO_Unary_Length (unsigned long val)
55{
56 register unsigned long num;
57 num = bitio_buffer::unary_length(val);
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 num = bitio_buffer::binary_length (val, b);
68 return (num);
69}
70
71
72unsigned long BIO_Gamma_Length (unsigned long val) {
73 register unsigned long num;
74 num = bitio_buffer::gamma_length(val);
75 return (num);
76}
77
78
79unsigned long
80BIO_Delta_Length (unsigned long val)
81{
82 register unsigned long num;
83 num = bitio_buffer::delta_length(val);
84 return (num);
85}
86
87
88unsigned long
89BIO_Elias_Length (unsigned long val, unsigned long b, double s)
90{
91 register unsigned long num;
92 num = bitio_buffer::elias_length(val, b, s);
93 return (num);
94}
95
96unsigned long
97BIO_Bblock_Length (unsigned long val, unsigned long b)
98{
99 register unsigned long num;
100 num = bitio_buffer::bblock_length (val, b);
101 return (num);
102}
103
104
105int
106BIO_Bblock_Init (int N, int p)
107{
108 int b;
109 b = (int) (0.5 + 0.6931471 * N / p);
110 return (b ? b : 1);
111}
112
113
114int
115BIO_Bblock_Init_W (int N, int p)
116{
117 int logb;
118 logb = bitio_buffer::floor_log2 ((N - p) / p);
119 return (logb < 0 ? 1 : (1 << logb));
120}
121
122int
123BIO_Bblock_Bound_b (int N, int p, int b)
124{
125 int clogb;
126 clogb = bitio_buffer::ceil_log2 (b);
127 return (p * (1 + clogb) + (N - p * ((1 << clogb) - b + 1)) / b);
128}
129
130int
131BIO_Bblock_Bound (int N, int p)
132{
133 int b;
134 b = BIO_Bblock_Init_W (N, p);
135 return (BIO_Bblock_Bound_b (N, p, b));
136}
137
138/* adjustment is a hack to overcome inaccuracies in floating point,
139 where (int)(ln4/ln2) can equal 1, not 2. */
140int
141BIO_Gamma_Bound (int N, int p)
142{
143 return ((int) (p * (2 * log2 (((double) N * 1.0001) / p) + 1)));
144}
145
146int
147floorlog_2 (int b)
148{
149 int logb;
150 logb = bitio_buffer::floor_log2 (b);
151 return logb;
152}
153
154int
155ceillog_2 (int b)
156{
157 int logb;
158 logb = bitio_buffer::ceil_log2 (b);
159 return logb;
160}
Note: See TracBrowser for help on using the repository browser.