thwack.h 2.0 KB

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