99 */
1010
1111/*-----------------------------------------------------------------------------
12-
12+
1313If you want to understand the MurmurHash algorithm you would be much better
1414off reading the original source. Just point your browser at:
1515http://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.
6969
7070/* Find best way to ROTL */
7171#if defined(_MSC_VER )
72- #define FORCE_INLINE __forceinline
72+ #define FORCE_INLINE static __forceinline
7373 #include <stdlib.h> /* Microsoft put _rotl declaration in here */
7474 #define ROTL32 (x ,y ) _rotl(x,y)
7575#else
76- #define FORCE_INLINE inline __attribute__ ((always_inline))
76+ #define FORCE_INLINE static inline __attribute__((always_inline))
7777 /* gcc recognises this code and generates a rotate instruction for CPUs with one */
7878 #define ROTL32 (x ,r ) (((uint32_t)x << r) | ((uint32_t)x >> (32 - r)))
7979#endif
8080
8181#include "endianness.h"
8282
83- #define READ_UINT32 (ptr ) getblock32((uint32_t *)ptr)
83+ #define READ_UINT32 (ptr ) getblock32((uint32_t *)ptr, 0 )
8484
8585/*-----------------------------------------------------------------------------
8686 * Core murmurhash algorithm macros */
@@ -90,31 +90,31 @@ static const uint32_t kC2 = 0x1b873593;
9090
9191/* This is the main processing body of the algorithm. It operates
9292 * 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)
103103
104104/* Append unaligned bytes to carry, forcing hash churn if we have 4 bytes */
105105/* 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)
118118
119119/*---------------------------------------------------------------------------*/
120120
@@ -200,7 +200,7 @@ void PMurHash32_Process(uint32_t *ph1, uint32_t *pcarry, const void *key, int le
200200 /* Copy out new running hash and carry */
201201 * ph1 = h1 ;
202202 * pcarry = (c & ~0xff ) | n ;
203- }
203+ }
204204
205205/*---------------------------------------------------------------------------*/
206206
@@ -224,23 +224,3 @@ uint32_t PMurHash32_Result(uint32_t h, uint32_t carry, uint32_t total_length)
224224
225225 return h ;
226226}
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