xref: /plan9/sys/src/cmd/gs/src/sbwbs.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1994, 1995 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: sbwbs.h,v 1.4 2002/02/21 22:24:53 giles Exp $ */
18 /* Definitions for BWBlockSort (Burroughs-Wheeler) filters */
19 /* Requires scommon.h; strimpl.h if any templates are referenced */
20 
21 #ifndef sbwbs_INCLUDED
22 #  define sbwbs_INCLUDED
23 
24 /* Common framework for streams that buffer a block for processing */
25 #define stream_buffered_state_common\
26 	stream_state_common;\
27 		/* The client may set the following before initialization, */\
28 		/* or the stream may set it later. */\
29 	int BlockSize;\
30 		/* The init procedure sets the following, */\
31 		/* if BlockSize has been set. */\
32 	byte *buffer;		/* [BlockSize] */\
33 		/* The following are updated dynamically. */\
34 	bool filling;		/* true if filling buffer, */\
35 				/* false if emptying */\
36 	int bsize;		/* size of current block (<= BlockSize) */\
37 	int bpos		/* current index within buffer */
38 typedef struct stream_buffered_state_s {
39     stream_buffered_state_common;
40 } stream_buffered_state;
41 
42 #define private_st_buffered_state()	/* in sbwbs.c */\
43   gs_private_st_ptrs1(st_buffered_state, stream_buffered_state,\
44     "stream_buffered state", sbuf_enum_ptrs, sbuf_reloc_ptrs, buffer)
45 
46 /* BWBlockSortEncode/Decode */
47 typedef struct of_ {
48     uint v[256];
49 } offsets_full;
50 typedef struct stream_BWBS_state_s {
51     stream_buffered_state_common;
52     /* The init procedure sets the following. */
53     void *offsets;		/* permutation indices when writing, */
54     /* multi-level indices when reading */
55     /* The following are updated dynamically. */
56     int N;			/* actual length of block */
57     /* The following are only used when decoding. */
58     int I;			/* index of unrotated string */
59     int i;			/* next index in encoded string */
60 } stream_BWBS_state;
61 typedef stream_BWBS_state stream_BWBSE_state;
62 typedef stream_BWBS_state stream_BWBSD_state;
63 
64 #define private_st_BWBS_state()	/* in sbwbs.c */\
65   gs_private_st_suffix_add1(st_BWBS_state, stream_BWBS_state,\
66     "BWBlockSortEncode/Decode state", bwbs_enum_ptrs, bwbs_reloc_ptrs,\
67     st_buffered_state, offsets)
68 extern const stream_template s_BWBSE_template;
69 extern const stream_template s_BWBSD_template;
70 
71 #endif /* sbwbs_INCLUDED */
72