1*b1efbcd6SAlok Aggarwal /* LzHash.h -- HASH functions for LZ algorithms 2*b1efbcd6SAlok Aggarwal 2008-10-04 : Igor Pavlov : Public domain */ 3*b1efbcd6SAlok Aggarwal 4*b1efbcd6SAlok Aggarwal #ifndef __LZHASH_H 5*b1efbcd6SAlok Aggarwal #define __LZHASH_H 6*b1efbcd6SAlok Aggarwal 7*b1efbcd6SAlok Aggarwal #define kHash2Size (1 << 10) 8*b1efbcd6SAlok Aggarwal #define kHash3Size (1 << 16) 9*b1efbcd6SAlok Aggarwal #define kHash4Size (1 << 20) 10*b1efbcd6SAlok Aggarwal 11*b1efbcd6SAlok Aggarwal #define kFix3HashSize (kHash2Size) 12*b1efbcd6SAlok Aggarwal #define kFix4HashSize (kHash2Size + kHash3Size) 13*b1efbcd6SAlok Aggarwal #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) 14*b1efbcd6SAlok Aggarwal 15*b1efbcd6SAlok Aggarwal #define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8); 16*b1efbcd6SAlok Aggarwal 17*b1efbcd6SAlok Aggarwal #define HASH3_CALC { \ 18*b1efbcd6SAlok Aggarwal UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 19*b1efbcd6SAlok Aggarwal hash2Value = temp & (kHash2Size - 1); \ 20*b1efbcd6SAlok Aggarwal hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } 21*b1efbcd6SAlok Aggarwal 22*b1efbcd6SAlok Aggarwal #define HASH4_CALC { \ 23*b1efbcd6SAlok Aggarwal UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 24*b1efbcd6SAlok Aggarwal hash2Value = temp & (kHash2Size - 1); \ 25*b1efbcd6SAlok Aggarwal hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 26*b1efbcd6SAlok Aggarwal hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; } 27*b1efbcd6SAlok Aggarwal 28*b1efbcd6SAlok Aggarwal #define HASH5_CALC { \ 29*b1efbcd6SAlok Aggarwal UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 30*b1efbcd6SAlok Aggarwal hash2Value = temp & (kHash2Size - 1); \ 31*b1efbcd6SAlok Aggarwal hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 32*b1efbcd6SAlok Aggarwal hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \ 33*b1efbcd6SAlok Aggarwal hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \ 34*b1efbcd6SAlok Aggarwal hash4Value &= (kHash4Size - 1); } 35*b1efbcd6SAlok Aggarwal 36*b1efbcd6SAlok Aggarwal /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ 37*b1efbcd6SAlok Aggarwal #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; 38*b1efbcd6SAlok Aggarwal 39*b1efbcd6SAlok Aggarwal 40*b1efbcd6SAlok Aggarwal #define MT_HASH2_CALC \ 41*b1efbcd6SAlok Aggarwal hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); 42*b1efbcd6SAlok Aggarwal 43*b1efbcd6SAlok Aggarwal #define MT_HASH3_CALC { \ 44*b1efbcd6SAlok Aggarwal UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 45*b1efbcd6SAlok Aggarwal hash2Value = temp & (kHash2Size - 1); \ 46*b1efbcd6SAlok Aggarwal hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } 47*b1efbcd6SAlok Aggarwal 48*b1efbcd6SAlok Aggarwal #define MT_HASH4_CALC { \ 49*b1efbcd6SAlok Aggarwal UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 50*b1efbcd6SAlok Aggarwal hash2Value = temp & (kHash2Size - 1); \ 51*b1efbcd6SAlok Aggarwal hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 52*b1efbcd6SAlok Aggarwal hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } 53*b1efbcd6SAlok Aggarwal 54*b1efbcd6SAlok Aggarwal #endif 55