hash.mx raw

   1  package iskra
   2  
   3  import "git.smesh.lol/iskradb/lattice"
   4  
   5  const (
   6  	fnvOffset64 uint64 = 14695981039346656037
   7  	fnvPrime64  uint64 = 1099511628211
   8  )
   9  
  10  // HashBytes computes 56-bit FNV-1a hash, discarding the top 8 bits.
  11  func HashBytes(data []byte) uint64 {
  12  	h := fnvOffset64
  13  	for _, c := range data {
  14  		h ^= uint64(c)
  15  		h *= fnvPrime64
  16  	}
  17  	return h >> 8
  18  }
  19  
  20  // SegmentKey builds a 64-bit key for a segment at a given stage.
  21  func SegmentKey(stage uint8, content []byte) lattice.Key {
  22  	return MakeCodeKey(stage, HashBytes(content))
  23  }
  24