1 |
adcroft |
1.1 |
/* |
2 |
|
|
** Copyright (C) 1995, 1996, 1997, 1998 Hewlett-Packard Company |
3 |
|
|
** Originally by Kevin Hughes, kev@kevcom.com, 3/11/94 |
4 |
|
|
** |
5 |
|
|
** This program and library is free software; you can redistribute it and/or |
6 |
|
|
** modify it under the terms of the GNU (Library) General Public License |
7 |
|
|
** as published by the Free Software Foundation; either version 2 |
8 |
|
|
** of the License, or any later version. |
9 |
|
|
** |
10 |
|
|
** This program is distributed in the hope that it will be useful, |
11 |
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
** GNU (Library) General Public License for more details. |
14 |
|
|
** |
15 |
|
|
** You should have received a copy of the GNU (Library) General Public License |
16 |
|
|
** along with this program; if not, write to the Free Software |
17 |
|
|
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
void compress1(int num, FILE *fp, int (*f_putc)(int , FILE *)); |
21 |
|
|
/* unsigned char *compress2(int num, unsigned char *buffer);*/ |
22 |
|
|
unsigned char *compress3(int num, unsigned char *buffer); |
23 |
|
|
|
24 |
|
|
int uncompress1(FILE *fp, int (*f_getc)(FILE *fp)); |
25 |
|
|
int uncompress2(unsigned char **buffer); |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
unsigned long PACKLONG(unsigned long num); |
29 |
|
|
void PACKLONG2(unsigned long num, unsigned char *buffer); |
30 |
|
|
|
31 |
|
|
unsigned long UNPACKLONG(unsigned long num); |
32 |
|
|
unsigned long UNPACKLONG2(unsigned char *buffer); |
33 |
|
|
|
34 |
|
|
unsigned char *compress_location(SWISH *,IndexFILE *, LOCATION *); |
35 |
|
|
void compress_location_values(unsigned char **buf,unsigned char **flagp,int filenum,int frequency, int *position); |
36 |
|
|
void compress_location_positions(unsigned char **buf,unsigned char *flag,int frequency, int *position); |
37 |
|
|
|
38 |
|
|
LOCATION *uncompress_location(SWISH *,IndexFILE *,unsigned char *); |
39 |
|
|
void uncompress_location_values(unsigned char **buf,unsigned char *flag, int *filenum,int *frequency); |
40 |
|
|
void uncompress_location_positions(unsigned char **buf, unsigned char flag, int frequency, int *position); |
41 |
|
|
|
42 |
|
|
void CompressCurrentLocEntry(SWISH *,IndexFILE *,ENTRY *); |
43 |
|
|
|
44 |
|
|
void SwapLocData(SWISH *,ENTRY *,unsigned char *,int); |
45 |
|
|
void unSwapLocData(SWISH *,int, ENTRY *); |
46 |
|
|
void sortSwapLocData(SWISH * , ENTRY *); |
47 |
|
|
void unSwapLocDataEntry_old(SWISH *,ENTRY *); |
48 |
|
|
|
49 |
|
|
/* Here is the worst case size for a compressed number |
50 |
|
|
** MAXINTCOMPSIZE stands for MAXimum INTeger COMPressed SIZE |
51 |
|
|
** |
52 |
|
|
** There are many places in the code in which we allocate |
53 |
|
|
** space for a compressed number. In the worst case this size is 5 |
54 |
|
|
** for 32 bit number, 10 for a 64 bit number. |
55 |
|
|
** |
56 |
|
|
** The way this compression works is reserving the first bit |
57 |
|
|
** in each byte to store a flag. The flag is set in all bytes |
58 |
|
|
** except for the last one. |
59 |
|
|
** This only gives 7 bits per byte to store the number. |
60 |
|
|
** |
61 |
|
|
** For example, to store 1000 (binary 1111101000) we will get: |
62 |
|
|
** |
63 |
|
|
** 1st byte 2th byte |
64 |
|
|
** 10000111 01101000 |
65 |
|
|
** ^ ^ |
66 |
|
|
** | | |
67 |
|
|
** | Flag to indicate that this is tha last byte |
68 |
|
|
** | |
69 |
|
|
** Flag set to indicate that more bytes follow this one |
70 |
|
|
** |
71 |
|
|
** So, to compress a 32 bit number we need 5 bytes and for |
72 |
|
|
** a 64 bit number we will use 10 bytes for the worst case |
73 |
|
|
*/ |
74 |
|
|
#define MAXINTCOMPSIZE (((sizeof(int) * 8) / 7) + (((sizeof(int) * 8) % 7) ? 1 : 0)) |
75 |
|
|
|