]> git.cworth.org Git - vogl/blob - src/voglcore/lzma_LzHash.h
Initial vogl checkin
[vogl] / src / voglcore / lzma_LzHash.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 /* LzHash.h -- HASH functions for LZ algorithms\r
28 2008-10-04 : Igor Pavlov : Public domain */\r
29 \r
30 #ifndef __LZHASH_H\r
31 #define __LZHASH_H\r
32 \r
33 #define kHash2Size (1 << 10)\r
34 #define kHash3Size (1 << 16)\r
35 #define kHash4Size (1 << 20)\r
36 \r
37 #define kFix3HashSize (kHash2Size)\r
38 #define kFix4HashSize (kHash2Size + kHash3Size)\r
39 #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r
40 \r
41 #define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r
42 \r
43 #define HASH3_CALC                                                \\r
44     {                                                             \\r
45         UInt32 temp = p->crc[cur[0]] ^ cur[1];                    \\r
46         hash2Value = temp & (kHash2Size - 1);                     \\r
47         hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; \\r
48     }\r
49 \r
50 #define HASH4_CALC                                                                        \\r
51     {                                                                                     \\r
52         UInt32 temp = p->crc[cur[0]] ^ cur[1];                                            \\r
53         hash2Value = temp & (kHash2Size - 1);                                             \\r
54         hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1);                   \\r
55         hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; \\r
56     }\r
57 \r
58 #define HASH5_CALC                                                           \\r
59     {                                                                        \\r
60         UInt32 temp = p->crc[cur[0]] ^ cur[1];                               \\r
61         hash2Value = temp & (kHash2Size - 1);                                \\r
62         hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1);      \\r
63         hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\r
64         hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask;      \\r
65         hash4Value &= (kHash4Size - 1);                                      \\r
66     }\r
67 \r
68 /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
69 #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
70 \r
71 #define MT_HASH2_CALC \\r
72     hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
73 \r
74 #define MT_HASH3_CALC                                                   \\r
75     {                                                                   \\r
76         UInt32 temp = p->crc[cur[0]] ^ cur[1];                          \\r
77         hash2Value = temp & (kHash2Size - 1);                           \\r
78         hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
79     }\r
80 \r
81 #define MT_HASH4_CALC                                                                           \\r
82     {                                                                                           \\r
83         UInt32 temp = p->crc[cur[0]] ^ cur[1];                                                  \\r
84         hash2Value = temp & (kHash2Size - 1);                                                   \\r
85         hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1);                         \\r
86         hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); \\r
87     }\r
88 \r
89 #endif\r