rlm@1: /* LzHash.h -- HASH functions for LZ algorithms rlm@1: 2008-10-04 : Igor Pavlov : Public domain */ rlm@1: rlm@1: #ifndef __LZHASH_H rlm@1: #define __LZHASH_H rlm@1: rlm@1: #define kHash2Size (1 << 10) rlm@1: #define kHash3Size (1 << 16) rlm@1: #define kHash4Size (1 << 20) rlm@1: rlm@1: #define kFix3HashSize (kHash2Size) rlm@1: #define kFix4HashSize (kHash2Size + kHash3Size) rlm@1: #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) rlm@1: rlm@1: #define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8); rlm@1: rlm@1: #define HASH3_CALC { \ rlm@1: UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ rlm@1: hash2Value = temp & (kHash2Size - 1); \ rlm@1: hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } rlm@1: rlm@1: #define HASH4_CALC { \ rlm@1: UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ rlm@1: hash2Value = temp & (kHash2Size - 1); \ rlm@1: hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ rlm@1: hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; } rlm@1: rlm@1: #define HASH5_CALC { \ rlm@1: UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ rlm@1: hash2Value = temp & (kHash2Size - 1); \ rlm@1: hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ rlm@1: hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \ rlm@1: hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \ rlm@1: hash4Value &= (kHash4Size - 1); } rlm@1: rlm@1: /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ rlm@1: #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; rlm@1: rlm@1: rlm@1: #define MT_HASH2_CALC \ rlm@1: hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); rlm@1: rlm@1: #define MT_HASH3_CALC { \ rlm@1: UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ rlm@1: hash2Value = temp & (kHash2Size - 1); \ rlm@1: hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } rlm@1: rlm@1: #define MT_HASH4_CALC { \ rlm@1: UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ rlm@1: hash2Value = temp & (kHash2Size - 1); \ rlm@1: hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ rlm@1: hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } rlm@1: rlm@1: #endif