LzHash.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* LzHash.h -- HASH functions for LZ algorithms
  2. 2015-04-12 : Igor Pavlov : Public domain */
  3. #ifndef __LZ_HASH_H
  4. #define __LZ_HASH_H
  5. #define kHash2Size (1 << 10)
  6. #define kHash3Size (1 << 16)
  7. #define kHash4Size (1 << 20)
  8. #define kFix3HashSize (kHash2Size)
  9. #define kFix4HashSize (kHash2Size + kHash3Size)
  10. #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
  11. #define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);
  12. #define HASH3_CALC { \
  13. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  14. h2 = temp & (kHash2Size - 1); \
  15. hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
  16. #define HASH4_CALC { \
  17. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  18. h2 = temp & (kHash2Size - 1); \
  19. temp ^= ((UInt32)cur[2] << 8); \
  20. h3 = temp & (kHash3Size - 1); \
  21. hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
  22. #define HASH5_CALC { \
  23. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  24. h2 = temp & (kHash2Size - 1); \
  25. temp ^= ((UInt32)cur[2] << 8); \
  26. h3 = temp & (kHash3Size - 1); \
  27. temp ^= (p->crc[cur[3]] << 5); \
  28. h4 = temp & (kHash4Size - 1); \
  29. hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }
  30. /* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
  31. #define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
  32. #define MT_HASH2_CALC \
  33. h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
  34. #define MT_HASH3_CALC { \
  35. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  36. h2 = temp & (kHash2Size - 1); \
  37. h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
  38. #define MT_HASH4_CALC { \
  39. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  40. h2 = temp & (kHash2Size - 1); \
  41. temp ^= ((UInt32)cur[2] << 8); \
  42. h3 = temp & (kHash3Size - 1); \
  43. h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
  44. #endif