fnv.go 604 B

1234567891011121314151617181920212223242526272829
  1. package prometheus
  2. // Inline and byte-free variant of hash/fnv's fnv64a.
  3. const (
  4. offset64 = 14695981039346656037
  5. prime64 = 1099511628211
  6. )
  7. // hashNew initializies a new fnv64a hash value.
  8. func hashNew() uint64 {
  9. return offset64
  10. }
  11. // hashAdd adds a string to a fnv64a hash value, returning the updated hash.
  12. func hashAdd(h uint64, s string) uint64 {
  13. for i := 0; i < len(s); i++ {
  14. h ^= uint64(s[i])
  15. h *= prime64
  16. }
  17. return h
  18. }
  19. // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash.
  20. func hashAddByte(h uint64, b byte) uint64 {
  21. h ^= uint64(b)
  22. h *= prime64
  23. return h
  24. }