VictoriaMetrics/lib/logstorage/hash128.go
2023-07-06 17:30:05 -07:00

38 lines
534 B
Go

package logstorage
import (
"sync"
"github.com/cespare/xxhash/v2"
)
func hash128(data []byte) u128 {
h := getHasher()
_, _ = h.Write(data)
hi := h.Sum64()
_, _ = h.Write(magicSuffixForHash)
lo := h.Sum64()
putHasher(h)
return u128{
hi: hi,
lo: lo,
}
}
var magicSuffixForHash = []byte("magic!")
func getHasher() *xxhash.Digest {
v := hasherPool.Get()
if v == nil {
return xxhash.New()
}
return v.(*xxhash.Digest)
}
func putHasher(h *xxhash.Digest) {
h.Reset()
hasherPool.Put(h)
}
var hasherPool sync.Pool