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