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