Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Hash_impl
diff MurmurHash2.c @ 14:5b89d57e5d10
added .brch__VMS__malloc_brch which has purpose of the brch
| author | Me@portablequad |
|---|---|
| date | Sat, 11 Feb 2012 17:55:51 -0800 |
| parents | 1218b245530c |
| children |
line diff
1.1 --- a/MurmurHash2.c Thu Feb 09 15:51:22 2012 +0100 1.2 +++ b/MurmurHash2.c Sat Feb 11 17:55:51 2012 -0800 1.3 @@ -1,64 +1,69 @@ 1.4 -//----------------------------------------------------------------------------- 1.5 -// MurmurHash2, by Austin Appleby 1.6 - 1.7 -// Note - This code makes a few assumptions about how your machine behaves - 1.8 - 1.9 -// 1. We can read a 4-byte value from any address without crashing 1.10 -// 2. sizeof(int) == 4 1.11 - 1.12 -// And it has a few limitations - 1.13 - 1.14 -// 1. It will not work incrementally. 1.15 -// 2. It will not produce the same results on little-endian and big-endian 1.16 -// machines. 1.17 - 1.18 -unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) 1.19 -{ 1.20 - // 'm' and 'r' are mixing constants generated offline. 1.21 - // They're not really 'magic', they just happen to work well. 1.22 - 1.23 - const unsigned int m = 0x5bd1e995; 1.24 - const int r = 24; 1.25 - 1.26 - // Initialize the hash to a 'random' value 1.27 - 1.28 - unsigned int h = seed ^ len; 1.29 - 1.30 - // Mix 4 bytes at a time into the hash 1.31 - 1.32 - const unsigned char * data = (const unsigned char *)key; 1.33 - 1.34 - while(len >= 4) 1.35 - { 1.36 - unsigned int k = *(unsigned int *)data; 1.37 - 1.38 - k *= m; 1.39 - k ^= k >> r; 1.40 - k *= m; 1.41 - 1.42 - h *= m; 1.43 - h ^= k; 1.44 - 1.45 - data += 4; 1.46 - len -= 4; 1.47 - } 1.48 - 1.49 - // Handle the last few bytes of the input array 1.50 - 1.51 - switch(len) 1.52 - { 1.53 - case 3: h ^= data[2] << 16; 1.54 - case 2: h ^= data[1] << 8; 1.55 - case 1: h ^= data[0]; 1.56 - h *= m; 1.57 - }; 1.58 - 1.59 - // Do a few final mixes of the hash to ensure the last few 1.60 - // bytes are well-incorporated. 1.61 - 1.62 - h ^= h >> 13; 1.63 - h *= m; 1.64 - h ^= h >> 15; 1.65 - 1.66 - return h; 1.67 -} 1.68 + 1.69 +/*This file is sample code pulled off the web -- NOT part of the compiled code 1.70 + * make sure it doesn't get included in makefile 'cause it doesn't compile 1.71 + */ 1.72 + 1.73 +//----------------------------------------------------------------------------- 1.74 +// MurmurHash2, by Austin Appleby 1.75 + 1.76 +// Note - This code makes a few assumptions about how your machine behaves - 1.77 + 1.78 +// 1. We can read a 4-byte value from any address without crashing 1.79 +// 2. sizeof(int) == 4 1.80 + 1.81 +// And it has a few limitations - 1.82 + 1.83 +// 1. It will not work incrementally. 1.84 +// 2. It will not produce the same results on little-endian and big-endian 1.85 +// machines. 1.86 + 1.87 +unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) 1.88 +{ 1.89 + // 'm' and 'r' are mixing constants generated offline. 1.90 + // They're not really 'magic', they just happen to work well. 1.91 + 1.92 + const unsigned int m = 0x5bd1e995; 1.93 + const int r = 24; 1.94 + 1.95 + // Initialize the hash to a 'random' value 1.96 + 1.97 + unsigned int h = seed ^ len; 1.98 + 1.99 + // Mix 4 bytes at a time into the hash 1.100 + 1.101 + const unsigned char * data = (const unsigned char *)key; 1.102 + 1.103 + while(len >= 4) 1.104 + { 1.105 + unsigned int k = *(unsigned int *)data; 1.106 + 1.107 + k *= m; 1.108 + k ^= k >> r; 1.109 + k *= m; 1.110 + 1.111 + h *= m; 1.112 + h ^= k; 1.113 + 1.114 + data += 4; 1.115 + len -= 4; 1.116 + } 1.117 + 1.118 + // Handle the last few bytes of the input array 1.119 + 1.120 + switch(len) 1.121 + { 1.122 + case 3: h ^= data[2] << 16; 1.123 + case 2: h ^= data[1] << 8; 1.124 + case 1: h ^= data[0]; 1.125 + h *= m; 1.126 + }; 1.127 + 1.128 + // Do a few final mixes of the hash to ensure the last few 1.129 + // bytes are well-incorporated. 1.130 + 1.131 + h ^= h >> 13; 1.132 + h *= m; 1.133 + h ^= h >> 15; 1.134 + 1.135 + return h; 1.136 +}
