PMurHash.h (1982B)
1 /*----------------------------------------------------------------------------- 2 * MurmurHash3 was written by Austin Appleby, and is placed in the public 3 * domain. 4 * 5 * This implementation was written by Shane Day, and is also public domain. 6 * 7 * This is a portable ANSI C implementation of MurmurHash3_x86_32 (Murmur3A) 8 * with support for progressive processing. 9 */ 10 11 /* ------------------------------------------------------------------------- */ 12 /* Determine what native type to use for uint32_t */ 13 14 /* We can't use the name 'uint32_t' here because it will conflict with 15 * any version provided by the system headers or application. */ 16 17 /* First look for special cases */ 18 #if defined(_MSC_VER) 19 #define MH_UINT32 unsigned long 20 #endif 21 22 /* If the compiler says it's C99 then take its word for it */ 23 #if !defined(MH_UINT32) && ( \ 24 defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) 25 #include <stdint.h> 26 #define MH_UINT32 uint32_t 27 #endif 28 29 /* Otherwise try testing against max value macros from limit.h */ 30 #if !defined(MH_UINT32) 31 #include <limits.h> 32 #if (USHRT_MAX == 0xffffffffUL) 33 #define MH_UINT32 unsigned short 34 #elif (UINT_MAX == 0xffffffffUL) 35 #define MH_UINT32 unsigned int 36 #elif (ULONG_MAX == 0xffffffffUL) 37 #define MH_UINT32 unsigned long 38 #endif 39 #endif 40 41 #if !defined(MH_UINT32) 42 #error Unable to determine type name for unsigned 32-bit int 43 #endif 44 45 /* I'm yet to work on a platform where 'unsigned char' is not 8 bits */ 46 #define MH_UINT8 unsigned char 47 48 49 /* ------------------------------------------------------------------------- */ 50 /* Prototypes */ 51 52 #ifdef __cplusplus 53 extern "C" { 54 #endif 55 56 void PMurHash32_Process(MH_UINT32 *ph1, MH_UINT32 *pcarry, const void *key, int len); 57 MH_UINT32 PMurHash32_Result(MH_UINT32 h1, MH_UINT32 carry, MH_UINT32 total_length); 58 MH_UINT32 PMurHash32(MH_UINT32 seed, const void *key, int len); 59 60 void PMurHash32_test(const void *key, int len, MH_UINT32 seed, void *out); 61 62 #ifdef __cplusplus 63 } 64 #endif