9
9
*/
10
10
11
11
/*-----------------------------------------------------------------------------
12
-
12
+
13
13
If you want to understand the MurmurHash algorithm you would be much better
14
14
off reading the original source. Just point your browser at:
15
15
http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp
@@ -69,18 +69,18 @@ on big endian machines, or a byte-by-byte read if the endianess is unknown.
69
69
70
70
/* Find best way to ROTL */
71
71
#if defined(_MSC_VER )
72
- #define FORCE_INLINE __forceinline
72
+ #define FORCE_INLINE static __forceinline
73
73
#include <stdlib.h> /* Microsoft put _rotl declaration in here */
74
74
#define ROTL32 (x ,y ) _rotl(x,y)
75
75
#else
76
- #define FORCE_INLINE inline __attribute__ ((always_inline))
76
+ #define FORCE_INLINE static inline __attribute__((always_inline))
77
77
/* gcc recognises this code and generates a rotate instruction for CPUs with one */
78
78
#define ROTL32 (x ,r ) (((uint32_t)x << r) | ((uint32_t)x >> (32 - r)))
79
79
#endif
80
80
81
81
#include "endianness.h"
82
82
83
- #define READ_UINT32 (ptr ) getblock32((uint32_t *)ptr)
83
+ #define READ_UINT32 (ptr ) getblock32((uint32_t *)ptr, 0 )
84
84
85
85
/*-----------------------------------------------------------------------------
86
86
* Core murmurhash algorithm macros */
@@ -90,31 +90,31 @@ static const uint32_t kC2 = 0x1b873593;
90
90
91
91
/* This is the main processing body of the algorithm. It operates
92
92
* on each full 32-bits of input. */
93
- FORCE_INLINE void doblock (uint32_t & h1, uint32_t & k1)
94
- {
95
- k1 *= kC1 ;
96
- k1 = ROTL32 (k1,15 );
97
- k1 *= kC2 ;
98
-
99
- h1 ^= k1;
100
- h1 = ROTL32 (h1,13 );
101
- h1 = h1*5 +0xe6546b64 ;
102
- }
93
+ #define doblock (h1 , k1 ) \
94
+ do {\
95
+ k1 *= kC1;\
96
+ k1 = ROTL32(k1,15);\
97
+ k1 *= kC2;\
98
+ \
99
+ h1 ^= k1;\
100
+ h1 = ROTL32(h1,13);\
101
+ h1 = h1*5+0xe6546b64;\
102
+ } while(0)
103
103
104
104
/* Append unaligned bytes to carry, forcing hash churn if we have 4 bytes */
105
105
/* cnt=bytes to process, h1=name of h1 var, c=carry, n=bytes in c, ptr/len=payload */
106
- FORCE_INLINE void dobytes (int cnt, uint32_t & h1, uint32_t & c, int &n,
107
- const uint8_t *&ptr, int &len)
108
- {
109
- while (cnt --) {
110
- c = c>>8 | (uint32_t )*ptr++<<24 ;
111
- n++; len--;
112
- if (n==4 ) {
113
- doblock (h1, c);
114
- n = 0 ;
115
- }
116
- }
117
- }
106
+ #define dobytes (cnt , h1 , c , n , ptr , len ) \
107
+ do {\
108
+ unsigned __cnt = cnt;\
109
+ while(__cnt --) {\
110
+ c = c>>8 | (uint32_t)*ptr++<<24;\
111
+ n++; len--;\
112
+ if(n==4) {\
113
+ doblock(h1, c);\
114
+ n = 0;\
115
+ }\
116
+ }\
117
+ } while(0)
118
118
119
119
/*---------------------------------------------------------------------------*/
120
120
@@ -200,7 +200,7 @@ void PMurHash32_Process(uint32_t *ph1, uint32_t *pcarry, const void *key, int le
200
200
/* Copy out new running hash and carry */
201
201
* ph1 = h1 ;
202
202
* pcarry = (c & ~0xff ) | n ;
203
- }
203
+ }
204
204
205
205
/*---------------------------------------------------------------------------*/
206
206
@@ -224,23 +224,3 @@ uint32_t PMurHash32_Result(uint32_t h, uint32_t carry, uint32_t total_length)
224
224
225
225
return h ;
226
226
}
227
-
228
-
229
- /* ---------------------------------------------------------------------------*/
230
-
231
- /* All in one go */
232
-
233
- uint32_t PMurHash32 (const void * key, int len, uint32_t seed)
234
- {
235
- uint32_t carry = 0 ;
236
- PMurHash32_Process (&seed, &carry, key, len);
237
- return PMurHash32_Result (seed, carry, (uint32_t ) len);
238
- }
239
-
240
- /* MurmurHash3_x86_32 api */
241
- void PMurHash32 (const void * key, int len, uint32_t seed, void * out)
242
- {
243
- uint32_t carry = 0 ;
244
- PMurHash32_Process (&seed, &carry, key, len);
245
- *(uint32_t *)out = PMurHash32_Result (seed, carry, (uint32_t ) len);
246
- }
0 commit comments