Debian Codegraph @

src/lzma/LzHash.h

raw
1 /* LzHash.h -- HASH functions for LZ algorithms
2 2008-10-04 : Igor Pavlov : Public domain */
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 2014
5 // David Freese, W1HKJ
6 //
7 // This file is part of flmsg
8 //
9 // flrig is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // flrig is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // ----------------------------------------------------------------------------
22
23 #ifndef __LZHASH_H
24 #define __LZHASH_H
25
26 #define kHash2Size (1 << 10)
27 #define kHash3Size (1 << 16)
28 #define kHash4Size (1 << 20)
29
30 #define kFix3HashSize (kHash2Size)
31 #define kFix4HashSize (kHash2Size + kHash3Size)
32 #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
33
34 #define HASH2_CALC hashValue = cur[0] | ((LZ_UInt32)cur[1] << 8);
35
36 #define HASH3_CALC { \
37 LZ_UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
38 hash2Value = temp & (kHash2Size - 1); \
39 hashValue = (temp ^ ((LZ_UInt32)cur[2] << 8)) & p->hashMask; }
40
41 #define HASH4_CALC { \
42 LZ_UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
43 hash2Value = temp & (kHash2Size - 1); \
44 hash3Value = (temp ^ ((LZ_UInt32)cur[2] << 8)) & (kHash3Size - 1); \
45 hashValue = (temp ^ ((LZ_UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
46
47 #define HASH5_CALC { \
48 LZ_UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
49 hash2Value = temp & (kHash2Size - 1); \
50 hash3Value = (temp ^ ((LZ_UInt32)cur[2] << 8)) & (kHash3Size - 1); \
51 hash4Value = (temp ^ ((LZ_UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
52 hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
53 hash4Value &= (kHash4Size - 1); }
54
55 /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((LZ_UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
56 #define HASH_ZIP_CALC hashValue = ((cur[2] | ((LZ_UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
57
58
59 #define MT_HASH2_CALC \
60 hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
61
62 #define MT_HASH3_CALC { \
63 LZ_UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
64 hash2Value = temp & (kHash2Size - 1); \
65 hash3Value = (temp ^ ((LZ_UInt32)cur[2] << 8)) & (kHash3Size - 1); }
66
67 #define MT_HASH4_CALC { \
68 LZ_UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
69 hash2Value = temp & (kHash2Size - 1); \
70 hash3Value = (temp ^ ((LZ_UInt32)cur[2] << 8)) & (kHash3Size - 1); \
71 hash4Value = (temp ^ ((LZ_UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
72
73 #endif