murmurhash3.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2022, smartmx <smartmx@qq.com>
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-04-03 smartmx the first version
  9. *
  10. */
  11. /*
  12. * @Note:
  13. * This is murmur3 hash algorithm: https://github.com/aappleby/smhasher.
  14. * But coded with c instead.
  15. * This repository only accomplish 32bit hash algorithm.
  16. */
  17. #ifndef _MURMURHASH3_H_
  18. #define _MURMURHASH3_H_
  19. #include "stdio.h"
  20. #include "stdint.h"
  21. /* The seed value, you can change as you want. */
  22. #define MURMURHASH3_SEED_VALUE 0x31313137
  23. /* The hash calculate parameters value, don't change it unless it's necessary. */
  24. #define MURMURHASH3_C1_VALUE 0xcc9e2d51
  25. #define MURMURHASH3_C2_VALUE 0x1b873593
  26. #define MURMURHASH3_R1_VALUE 15
  27. #define MURMURHASH3_R2_VALUE 13
  28. #define MURMURHASH3_M_VALUE 5
  29. #define MURMURHASH3_N_VALUE 0xe6546b64
  30. extern uint32_t murmurhash3_caculate32(const void *hash_key, uint32_t len);
  31. extern uint32_t murmurhash3_upper_caculate32(const void *hash_key, uint32_t len);
  32. extern uint8_t murmurhash3_lower_char_upper_memcmp(const void *src1, const void *src2, uint32_t len);
  33. #endif /* _MURMURHASH3_H_ */