github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/ingester/client/fnv.go (about)

     1  package client
     2  
     3  // hashAdd adds a string to a fnv64a hash value, returning the updated hash.
     4  func hashAddString(h uint64, s string) uint64 {
     5  	for i := 0; i < len(s); i++ {
     6  		h ^= uint64(s[i])
     7  		h *= prime64
     8  	}
     9  	return h
    10  }
    11  
    12  // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash.
    13  func hashAddByte(h uint64, b byte) uint64 {
    14  	h ^= uint64(b)
    15  	h *= prime64
    16  	return h
    17  }
    18  
    19  // hashAdd adds a string to a fnv64a hash value, returning the updated hash.
    20  // Note this is the same algorithm as Go stdlib `sum64a.Write()`
    21  func hashAdd(h uint64, s string) uint64 {
    22  	for i := 0; i < len(s); i++ {
    23  		h ^= uint64(s[i])
    24  		h *= prime64
    25  	}
    26  	return h
    27  }