LzHash.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* LzHash.h -- HASH functions for LZ algorithms
  2. 2008-10-04 : Igor Pavlov : Public domain */
  3. #ifndef __LZHASH_H
  4. #define __LZHASH_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 hashValue = cur[0] | ((UInt32)cur[1] << 8);
  12. #define HASH3_CALC { \
  13. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  14. hash2Value = temp & (kHash2Size - 1); \
  15. hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
  16. #define HASH4_CALC { \
  17. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  18. hash2Value = temp & (kHash2Size - 1); \
  19. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  20. hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
  21. #define HASH5_CALC { \
  22. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  23. hash2Value = temp & (kHash2Size - 1); \
  24. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  25. hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
  26. hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
  27. hash4Value &= (kHash4Size - 1); }
  28. /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
  29. #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
  30. #define MT_HASH2_CALC \
  31. hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
  32. #define MT_HASH3_CALC { \
  33. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  34. hash2Value = temp & (kHash2Size - 1); \
  35. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
  36. #define MT_HASH4_CALC { \
  37. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  38. hash2Value = temp & (kHash2Size - 1); \
  39. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  40. hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
  41. #endif