gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

73 行
1.8KB

  1. /*
  2. * Utilities for working with hash values.
  3. *
  4. * Portions Copyright (c) 2017-2019, PostgreSQL Global Development Group
  5. */
  6. #ifndef HASHUTILS_H
  7. #define HASHUTILS_H
  8. /*
  9. * Rotate the high 32 bits and the low 32 bits separately. The standard
  10. * hash function sometimes rotates the low 32 bits by one bit when
  11. * combining elements. We want extended hash functions to be compatible with
  12. * that algorithm when the seed is 0, so we can't just do a normal rotation.
  13. * This works, though.
  14. */
  15. #define ROTATE_HIGH_AND_LOW_32BITS(v) \
  16. ((((v) << 1) & UINT64CONST(0xfffffffefffffffe)) | \
  17. (((v) >> 31) & UINT64CONST(0x100000001)))
  18. extern Datum hash_any(register const unsigned char *k, register int keylen);
  19. extern Datum hash_any_extended(register const unsigned char *k,
  20. register int keylen, uint64 seed);
  21. extern Datum hash_uint32(uint32 k);
  22. extern Datum hash_uint32_extended(uint32 k, uint64 seed);
  23. /*
  24. * Combine two 32-bit hash values, resulting in another hash value, with
  25. * decent bit mixing.
  26. *
  27. * Similar to boost's hash_combine().
  28. */
  29. static inline uint32
  30. hash_combine(uint32 a, uint32 b)
  31. {
  32. a ^= b + 0x9e3779b9 + (a << 6) + (a >> 2);
  33. return a;
  34. }
  35. /*
  36. * Combine two 64-bit hash values, resulting in another hash value, using the
  37. * same kind of technique as hash_combine(). Testing shows that this also
  38. * produces good bit mixing.
  39. */
  40. static inline uint64
  41. hash_combine64(uint64 a, uint64 b)
  42. {
  43. /* 0x49a0f4dd15e5a8e3 is 64bit random data */
  44. a ^= b + UINT64CONST(0x49a0f4dd15e5a8e3) + (a << 54) + (a >> 7);
  45. return a;
  46. }
  47. /*
  48. * Simple inline murmur hash implementation hashing a 32 bit integer, for
  49. * performance.
  50. */
  51. static inline uint32
  52. murmurhash32(uint32 data)
  53. {
  54. uint32 h = data;
  55. h ^= h >> 16;
  56. h *= 0x85ebca6b;
  57. h ^= h >> 13;
  58. h *= 0xc2b2ae35;
  59. h ^= h >> 16;
  60. return h;
  61. }
  62. #endif /* HASHUTILS_H */
上海开阖软件有限公司 沪ICP备12045867号-1