De-C++ify murmur3 comments

This commit is contained in:
Raymond Pasco 2016-07-28 12:32:35 -07:00
parent 607ef00903
commit 36781ab5c6
2 changed files with 44 additions and 53 deletions

View File

@ -1,18 +1,18 @@
//-----------------------------------------------------------------------------
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
/*
MurmurHash3 was written by Austin Appleby, and is placed in the public
domain. The author hereby disclaims copyright to this source code.
// Note - The x86 and x64 versions do _not_ produce the same results, as the
// algorithms are optimized for their respective platforms. You can still
// compile and run any of them on any platform, but your performance with the
// non-native version will be less than optimal.
Note - The x86 and x64 versions do _not_ produce the same results, as the
algorithms are optimized for their respective platforms. You can still
compile and run any of them on any platform, but your performance with the
non-native version will be less than optimal.
*/
#include "MurmurHash3.h"
//-----------------------------------------------------------------------------
// Platform-specific functions and macros
/* Platform-specific functions and macros */
// Microsoft Visual Studio
/* Microsoft Visual Studio */
#if defined(_MSC_VER)
@ -25,9 +25,9 @@
#define BIG_CONSTANT(x) (x)
// Other compilers
/* Other compilers */
#else // defined(_MSC_VER)
#else /* defined(_MSC_VER) */
#define FORCE_INLINE inline __attribute__((always_inline))
@ -46,11 +46,12 @@ FORCE_INLINE uint64_t rotl64 ( uint64_t x, int8_t r )
#define BIG_CONSTANT(x) (x##LLU)
#endif // !defined(_MSC_VER)
#endif /* !defined(_MSC_VER) */
//-----------------------------------------------------------------------------
// Block read - if your platform needs to do endian-swapping or can only
// handle aligned reads, do the conversion here
/*
Block read - if your platform needs to do endian-swapping or can only
handle aligned reads, do the conversion here
*/
FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i )
{
@ -62,8 +63,7 @@ FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, int i )
return p[i];
}
//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche
/* Finalization mix - force all bits of a hash block to avalanche */
FORCE_INLINE uint32_t fmix32 ( uint32_t h )
{
@ -76,7 +76,7 @@ FORCE_INLINE uint32_t fmix32 ( uint32_t h )
return h;
}
//----------
/*----------*/
FORCE_INLINE uint64_t fmix64 ( uint64_t k )
{
@ -89,7 +89,7 @@ FORCE_INLINE uint64_t fmix64 ( uint64_t k )
return k;
}
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
void MurmurHash3_x86_32 ( const void * key, int len,
uint32_t seed, void * out )
@ -103,8 +103,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
const uint32_t c1 = 0xcc9e2d51;
const uint32_t c2 = 0x1b873593;
//----------
// body
/* body */
const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
@ -121,8 +120,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
h1 = h1*5+0xe6546b64;
}
//----------
// tail
/* tail */
const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
@ -136,8 +134,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
/* finalization */
h1 ^= len;
@ -146,7 +143,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
*(uint32_t*)out = h1;
}
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
void MurmurHash3_x86_128 ( const void * key, const int len,
uint32_t seed, void * out )
@ -165,8 +162,7 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
const uint32_t c3 = 0x38b34ae5;
const uint32_t c4 = 0xa1e38b93;
//----------
// body
/* body */
const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
@ -194,8 +190,7 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
}
//----------
// tail
/* tail */
const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
@ -230,8 +225,7 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
/* finalization */
h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
@ -252,7 +246,7 @@ void MurmurHash3_x86_128 ( const void * key, const int len,
((uint32_t*)out)[3] = h4;
}
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
void MurmurHash3_x64_128 ( const void * key, const int len,
const uint32_t seed, void * out )
@ -267,8 +261,7 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
//----------
// body
/* body */
const uint64_t * blocks = (const uint64_t *)(data);
@ -286,8 +279,7 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
}
//----------
// tail
/* tail */
const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
@ -316,8 +308,7 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
};
//----------
// finalization
/* finalization */
h1 ^= len; h2 ^= len;
@ -334,4 +325,4 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
((uint64_t*)out)[1] = h2;
}
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/

View File

@ -1,14 +1,14 @@
//-----------------------------------------------------------------------------
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
/*
MurmurHash3 was written by Austin Appleby, and is placed in the public
domain. The author hereby disclaims copyright to this source code.
*/
#ifndef _MURMURHASH3_H_
#define _MURMURHASH3_H_
//-----------------------------------------------------------------------------
// Platform-specific functions and macros
/* Platform-specific functions and macros */
// Microsoft Visual Studio
/* Microsoft Visual Studio */
#if defined(_MSC_VER) && (_MSC_VER < 1600)
@ -16,15 +16,15 @@ typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
// Other compilers
/* Other compilers */
#else // defined(_MSC_VER)
#else /* defined(_MSC_VER) */
#include <stdint.h>
#endif // !defined(_MSC_VER)
#endif /* !defined(_MSC_VER) */
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
@ -32,6 +32,6 @@ void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out
void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out );
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
#endif // _MURMURHASH3_H_
#endif /* _MURMURHASH3_H_ */