source: trunk/gsdl3/src/packages/mg/lib/bitio_gen.c@ 13654

Last change on this file since 13654 was 13654, checked in by kjdon, 17 years ago

tidied up the top comments, removed Ids, and old log messages

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