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