source: indexers/trunk/mg/lib/huffman.h@ 15434

Last change on this file since 15434 was 15434, checked in by mdewsnip, 16 years ago

Removed the inclusion of sysfuncs.h from these two files, as it doesn't seem to be used in this case and causes nasty warnings when compiling the receptionist.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/**************************************************************************
2 *
3 * huffman.h -- Huffman coding functions
4 * Copyright (C) 1994 Neil Sharman
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#ifndef H_HUFFMAN
23#define H_HUFFMAN
24
25#include "filestats.h"
26
27
28#define MAX_HUFFCODE_LEN 31
29
30typedef struct huff_data
31 {
32 int num_codes;
33 int mincodelen;
34 int maxcodelen;
35 int lencount[MAX_HUFFCODE_LEN + 1];
36 unsigned long min_code[MAX_HUFFCODE_LEN + 1];
37 char *clens;
38 }
39huff_data;
40
41
42huff_data *Generate_Huffman_Data (int num, long *freqs, huff_data * data,
43 u_long * mem);
44
45unsigned long *Generate_Huffman_Codes (huff_data * data, u_long * mem);
46
47unsigned long **Generate_Huffman_Vals (huff_data * data, u_long * mem);
48
49int Write_Huffman_Data (FILE * f, huff_data * hd);
50
51int Read_Huffman_Data (FILE * f, huff_data * hd, u_long * mem, u_long * disk);
52
53int F_Read_Huffman_Data (File * f, huff_data * hd, u_long * mem, u_long * disk);
54
55/* Calculate the number of bits required to code the data with the
56 specified frequencies. Normally freqs and counts should point to
57 the same array. */
58double Calculate_Huffman_Size (int num, long *freqs, long *counts);
59
60
61
62#define HUFF_ENCODE(x, codes, lens) \
63 do { \
64 register int __i; \
65 register int __clen = (lens)[x]; \
66 register unsigned long __code = (codes)[x]; \
67 for (__i=__clen-1; __i>=0; --__i) \
68 ENCODE_BIT((__code >> __i) & 1); \
69 } while(0)
70
71#define HUFF_ENCODE_L(x, codes, lens, count) \
72 do { \
73 HUFF_ENCODE(x, codes, lens); \
74 (count) += (lens)[x]; \
75 } while(0)
76
77
78#define HUFF_DECODE(x, mcodes, values) \
79 do { \
80 register unsigned long *__min_code = (mcodes); \
81 register unsigned long *__mclen = __min_code; \
82 register unsigned long **__values = (values); \
83 register unsigned long __code = 0; \
84 do \
85 { \
86 DECODE_ADD(__code); \
87 } \
88 while (__code < *++__mclen); \
89 (x) = __values[__mclen - __min_code][__code - *__mclen]; \
90 } while(0);
91
92
93#define HUFF_DECODE_L(x, mcodes, values, count) \
94 do { \
95 register unsigned long *__min_code = (mcodes); \
96 register unsigned long *__mclen = __min_code; \
97 register unsigned long **__values = (values); \
98 register unsigned long __code = 0; \
99 do \
100 { \
101 DECODE_ADD(__code); \
102 (count)++; \
103 } \
104 while (__code < *++__mclen); \
105 (x) = __values[__mclen - __min_code][__code - *__mclen]; \
106 } while(0);
107
108
109
110#endif
Note: See TracBrowser for help on using the repository browser.