thwack.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct Thwack Thwack;
  10. typedef struct Unthwack Unthwack;
  11. typedef struct ThwBlock ThwBlock;
  12. typedef struct UnthwBlock UnthwBlock;
  13. enum
  14. {
  15. ThwStats = 8,
  16. ThwErrLen = 64, /* max length of error message from thwack or unthwack */
  17. ThwMaxBlock = 1600, /* max size of compressible block */
  18. HashLog = 12,
  19. HashSize = 1<<HashLog,
  20. HashMask = HashSize - 1,
  21. MinMatch = 3, /* shortest match possible */
  22. MaxOff = 8,
  23. OffBase = 6,
  24. MinDecode = 8, /* minimum bits to decode a match or lit; >= 8 */
  25. CompBlocks = 10, /* max blocks used to encode data */
  26. EWinBlocks = 64, /* blocks held in encoder window */
  27. DWinBlocks = EWinBlocks, /* blocks held in decoder window */
  28. MaxSeqMask = 8, /* number of bits in coding block mask */
  29. MaxSeqStart = 256 /* max offset of initial coding block */
  30. };
  31. struct ThwBlock
  32. {
  33. uint32_t seq; /* sequence number for this data */
  34. uint8_t acked; /* ok to use this block; the decoder has it */
  35. uint16_t begin; /* time of first byte in hash */
  36. uint8_t *edata; /* last byte of valid data */
  37. uint16_t maxoff; /* time of last valid hash entry */
  38. uint16_t *hash;
  39. uint8_t *data;
  40. };
  41. struct Thwack
  42. {
  43. QLock acklock; /* locks slot, blocks[].(acked|seq) */
  44. int slot; /* next block to use */
  45. ThwBlock blocks[EWinBlocks];
  46. uint16_t hash[EWinBlocks][HashSize];
  47. Block *data[EWinBlocks];
  48. };
  49. struct UnthwBlock
  50. {
  51. uint32_t seq; /* sequence number for this data */
  52. uint16_t maxoff; /* valid data in each block */
  53. uint8_t *data;
  54. };
  55. struct Unthwack
  56. {
  57. int slot; /* next block to use */
  58. char err[ThwErrLen];
  59. UnthwBlock blocks[DWinBlocks];
  60. uint8_t data[DWinBlocks][ThwMaxBlock];
  61. };
  62. void thwackinit(Thwack*);
  63. void thwackcleanup(Thwack *tw);
  64. void unthwackinit(Unthwack*);
  65. int thwack(Thwack*, int mustadd, uint8_t *dst, int ndst, Block *bsrc,
  66. uint32_t seq, uint32_t stats[ThwStats]);
  67. void thwackack(Thwack*, uint32_t seq, uint32_t mask);
  68. int unthwack(Unthwack*, uint8_t *dst, int ndst, uint8_t *src, int nsrc,
  69. uint32_t seq);
  70. uint32_t unthwackstate(Unthwack *ut, uint8_t *mask);
  71. int unthwackadd(Unthwack *ut, uint8_t *src, int nsrc, uint32_t seq);