PMurHash.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /* Determine what native type to use for uint32_t */
  12. /* We can't use the name 'uint32_t' here because it will conflict with
  13. * any version provided by the system headers or application. */
  14. /* If the compiler says it's C99 then take its word for it */
  15. #if !defined(MH_UINT32) && ( \
  16. defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L )
  17. #include <stdint.h>
  18. #define MH_UINT32 uint32_t
  19. #endif
  20. /* Otherwise try testing against max value macros from limit.h */
  21. #if !defined(MH_UINT32)
  22. #include <limits.h>
  23. #if (USHRT_MAX == 0xffffffffUL)
  24. #define MH_UINT32 unsigned short
  25. #elif (UINT_MAX == 0xffffffffUL)
  26. #define MH_UINT32 unsigned int
  27. #elif (ULONG_MAX == 0xffffffffUL)
  28. #define MH_UINT32 unsigned long
  29. #endif
  30. #endif
  31. #if !defined(MH_UINT32)
  32. #error Unable to determine type name for unsigned 32-bit int
  33. #endif
  34. /* I'm yet to work on a platform where 'unsigned char' is not 8 bits */
  35. #define MH_UINT8 unsigned char
  36. /* ------------------------------------------------------------------------- */
  37. /* Prototypes */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. void PMurHash32_Process(MH_UINT32 *ph1, MH_UINT32 *pcarry, const void *key, int len);
  42. MH_UINT32 PMurHash32_Result(MH_UINT32 h1, MH_UINT32 carry, MH_UINT32 total_length);
  43. MH_UINT32 PMurHash32(MH_UINT32 seed, const void *key, int len);
  44. void PMurHash32_test(const void *key, int len, MH_UINT32 seed, void *out);
  45. #ifdef __cplusplus
  46. }
  47. #endif