// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package xxhash provides a wrapper around the xxhash library for attribute hashing.
package xxhash // import "go.opentelemetry.io/otel/attribute/internal/xxhash" import ( ) // Hash wraps xxhash.Digest to provide an API friendly for hashing attribute values. type Hash struct { d *xxhash.Digest } // New returns a new initialized xxHash64 hasher. func () Hash { return Hash{d: xxhash.New()} } func ( Hash) ( uint64) Hash { var [8]byte binary.LittleEndian.PutUint64([:], ) // errors from Write are always nil for xxhash // if it returns an err then panic , := .d.Write([:]) if != nil { panic("xxhash write of uint64 failed: " + .Error()) } return } func ( Hash) ( bool) Hash { // nolint:revive // This is a hashing function. if { return .Uint64(1) } return .Uint64(0) } func ( Hash) ( float64) Hash { return .Uint64(math.Float64bits()) } func ( Hash) ( int64) Hash { return .Uint64(uint64()) // nolint:gosec // Overflow doesn't matter since we are hashing. } func ( Hash) ( string) Hash { // errors from WriteString are always nil for xxhash // if it returns an err then panic , := .d.WriteString() if != nil { panic("xxhash write of string failed: " + .Error()) } return } // Sum64 returns the current hash value. func ( Hash) () uint64 { return .d.Sum64() }