Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
typedef struct Thwack		Thwack;
2
typedef struct Unthwack		Unthwack;
3
typedef struct ThwBlock		ThwBlock;
4
typedef struct UnthwBlock	UnthwBlock;
5
 
6
enum
7
{
8
	ThwStats	= 8,
9
	ThwErrLen	= 64,		/* max length of error message from thwack or unthwack */
10
	ThwMaxBlock	= 1600,		/* max size of compressible block */
11
 
12
	HashLog		= 12,
13
	HashSize	= 1<<HashLog,
14
	HashMask	= HashSize - 1,
15
 
16
	MinMatch	= 3,		/* shortest match possible */
17
 
18
	MaxOff		= 8,
19
	OffBase		= 6,
20
 
21
	MinDecode	= 8,		/* minimum bits to decode a match or lit; >= 8 */
22
 
23
	CompBlocks	= 10,		/* max blocks used to encode data */
24
	EWinBlocks	= 64,		/* blocks held in encoder window */
25
	DWinBlocks	= EWinBlocks,	/* blocks held in decoder window */
26
 
27
	MaxSeqMask	= 8,		/* number of bits in coding block mask */
28
	MaxSeqStart	= 256		/* max offset of initial coding block */
29
};
30
 
31
struct ThwBlock
32
{
33
	ulong	seq;			/* sequence number for this data */
34
	uchar	acked;			/* ok to use this block; the decoder has it */
35
	ushort	begin;			/* time of first byte in hash */
36
	uchar	*edata;			/* last byte of valid data */
37
	ushort	maxoff;			/* time of last valid hash entry */
38
	ushort	*hash;
39
	uchar	*data;
40
};
41
 
42
struct Thwack
43
{
44
	QLock		acklock;	/* locks slot, blocks[].(acked|seq) */
45
	int		slot;		/* next block to use */
46
	ThwBlock	blocks[EWinBlocks];
47
	ushort		hash[EWinBlocks][HashSize];
48
	Block		*data[EWinBlocks];
49
};
50
 
51
struct UnthwBlock
52
{
53
	ulong	seq;			/* sequence number for this data */
54
	ushort	maxoff;			/* valid data in each block */
55
	uchar	*data;
56
};
57
 
58
struct Unthwack
59
{
60
	int		slot;		/* next block to use */
61
	char		err[ThwErrLen];
62
	UnthwBlock	blocks[DWinBlocks];
63
	uchar		data[DWinBlocks][ThwMaxBlock];
64
};
65
 
66
void	thwackinit(Thwack*);
67
void	thwackcleanup(Thwack *tw);
68
void	unthwackinit(Unthwack*);
69
int	thwack(Thwack*, int mustadd, uchar *dst, int ndst, Block *bsrc, ulong seq, ulong stats[ThwStats]);
70
void	thwackack(Thwack*, ulong seq, ulong mask);
71
int	unthwack(Unthwack*, uchar *dst, int ndst, uchar *src, int nsrc, ulong seq);
72
ulong	unthwackstate(Unthwack *ut, uchar *mask);
73
int	unthwackadd(Unthwack *ut, uchar *src, int nsrc, ulong seq);