basics.go 656 B

123456789101112131415161718192021222324252627282930
  1. package farm
  2. // Some primes between 2^63 and 2^64 for various uses.
  3. const k0 uint64 = 0xc3a5c85c97cb3127
  4. const k1 uint64 = 0xb492b66fbe98f273
  5. const k2 uint64 = 0x9ae16a3b2f90404f
  6. // Magic numbers for 32-bit hashing. Copied from Murmur3.
  7. const c1 uint32 = 0xcc9e2d51
  8. const c2 uint32 = 0x1b873593
  9. // A 32-bit to 32-bit integer hash copied from Murmur3.
  10. func fmix(h uint32) uint32 {
  11. h ^= h >> 16
  12. h *= 0x85ebca6b
  13. h ^= h >> 13
  14. h *= 0xc2b2ae35
  15. h ^= h >> 16
  16. return h
  17. }
  18. func mur(a, h uint32) uint32 {
  19. // Helper from Murmur3 for combining two 32-bit values.
  20. a *= c1
  21. a = rotate32(a, 17)
  22. a *= c2
  23. h ^= a
  24. h = rotate32(h, 19)
  25. return h*5 + 0xe6546b64
  26. }