thwack.h 1.8 KB

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