Documentation
¶
Overview ¶
Package hash provides fast, predictable hash functions for Go's built-in types. It uses the standard hash.Hash64 interface and defaults to FNV-1 (Fowler–Noll–Vo) via hash/fnv.New64.
The helpers are designed for performance: values are encoded explicitly in little-endian form, and reflection or type assertions are avoided to minimize overhead.
This package intentionally does not provide generic hashing for structs or other composite types, nor does it attempt to combine multiple fields. The right approach depends on the use case and acceptable collision profile, so callers should implement hashing for their own composite types.
For example, XOR is very fast and order-insensitive, suitable for true sets, but it performs poorly with duplicates and can lead to high collision rates.
Index ¶
- type HashFunc
- func HashFuncForBool[T ~bool](h hash.Hash64) HashFunc[T]
- func HashFuncForBoolSlice[T ~[]bool](h hash.Hash64) HashFunc[T]
- func HashFuncForComplex64[T ~complex64](h hash.Hash64) HashFunc[T]
- func HashFuncForComplex64Slice[T ~[]complex64](h hash.Hash64) HashFunc[T]
- func HashFuncForComplex128[T ~complex128](h hash.Hash64) HashFunc[T]
- func HashFuncForComplex128Slice[T ~[]complex128](h hash.Hash64) HashFunc[T]
- func HashFuncForFloat32[T ~float32](h hash.Hash64) HashFunc[T]
- func HashFuncForFloat32Slice[T ~[]float32](h hash.Hash64) HashFunc[T]
- func HashFuncForFloat64[T ~float64](h hash.Hash64) HashFunc[T]
- func HashFuncForFloat64Slice[T ~[]float64](h hash.Hash64) HashFunc[T]
- func HashFuncForInt[T ~int](h hash.Hash64) HashFunc[T]
- func HashFuncForInt8[T ~int8](h hash.Hash64) HashFunc[T]
- func HashFuncForInt8Slice[T ~[]int8](h hash.Hash64) HashFunc[T]
- func HashFuncForInt16[T ~int16](h hash.Hash64) HashFunc[T]
- func HashFuncForInt16Slice[T ~[]int16](h hash.Hash64) HashFunc[T]
- func HashFuncForInt32[T ~int32](h hash.Hash64) HashFunc[T]
- func HashFuncForInt32Slice[T ~[]int32](h hash.Hash64) HashFunc[T]
- func HashFuncForInt64[T ~int64](h hash.Hash64) HashFunc[T]
- func HashFuncForInt64Slice[T ~[]int64](h hash.Hash64) HashFunc[T]
- func HashFuncForIntSlice[T ~[]int](h hash.Hash64) HashFunc[T]
- func HashFuncForString[T ~string](h hash.Hash64) HashFunc[T]
- func HashFuncForStringSlice[T ~[]string](h hash.Hash64) HashFunc[T]
- func HashFuncForUint[T ~uint](h hash.Hash64) HashFunc[T]
- func HashFuncForUint8[T ~uint8](h hash.Hash64) HashFunc[T]
- func HashFuncForUint8Slice[T ~[]uint8](h hash.Hash64) HashFunc[T]
- func HashFuncForUint16[T ~uint16](h hash.Hash64) HashFunc[T]
- func HashFuncForUint16Slice[T ~[]uint16](h hash.Hash64) HashFunc[T]
- func HashFuncForUint32[T ~uint32](h hash.Hash64) HashFunc[T]
- func HashFuncForUint32Slice[T ~[]uint32](h hash.Hash64) HashFunc[T]
- func HashFuncForUint64[T ~uint64](h hash.Hash64) HashFunc[T]
- func HashFuncForUint64Slice[T ~[]uint64](h hash.Hash64) HashFunc[T]
- func HashFuncForUintSlice[T ~[]uint](h hash.Hash64) HashFunc[T]
- func HashFuncForUintptr[T ~uintptr](h hash.Hash64) HashFunc[T]
- func HashFuncForUintptrSlice[T ~[]uintptr](h hash.Hash64) HashFunc[T]
- type Hasher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashFunc ¶
HashFunc defines a generic function type for hashing a key of type K.
func HashFuncForBool ¶
HashFuncForBool creates a HashFunc for boolean-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForBoolSlice ¶
HashFuncForBoolSlice creates a HashFunc for slice types with boolean elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForComplex64 ¶
HashFuncForComplex64 creates a HashFunc for complex64-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForComplex64Slice ¶
HashFuncForComplex64Slice creates a HashFunc for slice types with complex64 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForComplex128 ¶
func HashFuncForComplex128[T ~complex128](h hash.Hash64) HashFunc[T]
HashFuncForComplex128 creates a HashFunc for complex128-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForComplex128Slice ¶
func HashFuncForComplex128Slice[T ~[]complex128](h hash.Hash64) HashFunc[T]
HashFuncForComplex128Slice creates a HashFunc for slice types with complex128 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForFloat32 ¶
HashFuncForFloat32 creates a HashFunc for float32-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForFloat32Slice ¶
HashFuncForFloat32Slice creates a HashFunc for slice types with float32 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForFloat64 ¶
HashFuncForFloat64 creates a HashFunc for float64-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForFloat64Slice ¶
HashFuncForFloat64Slice creates a HashFunc for slice types with float64 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt ¶
HashFuncForInt creates a HashFunc for int-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt8 ¶
HashFuncForInt8 creates a HashFunc for int8-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt8Slice ¶
HashFuncForInt8Slice creates a HashFunc for slice types with int8 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt16 ¶
HashFuncForInt16 creates a HashFunc for int16-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt16Slice ¶
HashFuncForInt16Slice creates a HashFunc for slice types with int16 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt32 ¶
HashFuncForInt32 creates a HashFunc for int32-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt32Slice ¶
HashFuncForInt32Slice creates a HashFunc for slice types with int32 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt64 ¶
HashFuncForInt64 creates a HashFunc for int64-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForInt64Slice ¶
HashFuncForInt64Slice creates a HashFunc for slice types with int64 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForIntSlice ¶
HashFuncForIntSlice creates a HashFunc for slice types with int elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForString ¶
HashFuncForString creates a HashFunc for string-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForStringSlice ¶
HashFuncForStringSlice creates a HashFunc for slice types with string elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint ¶
HashFuncForUint creates a HashFunc for uint-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint8 ¶
HashFuncForUint8 creates a HashFunc for uint8-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint8Slice ¶
HashFuncForUint8Slice creates a HashFunc for slice types with uint8 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint16 ¶
HashFuncForUint16 creates a HashFunc for uint16-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint16Slice ¶
HashFuncForUint16Slice creates a HashFunc for slice types with uint16 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint32 ¶
HashFuncForUint32 creates a HashFunc for uint32-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint32Slice ¶
HashFuncForUint32Slice creates a HashFunc for slice types with uint32 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint64 ¶
HashFuncForUint64 creates a HashFunc for uint64-like types. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUint64Slice ¶
HashFuncForUint64Slice creates a HashFunc for slice types with uint64 elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUintSlice ¶
HashFuncForUintSlice creates a HashFunc for slice types with uint elements. If h is nil, a default hash.Hash64 implementation will be used.
func HashFuncForUintptr ¶
HashFuncForUintptr creates a HashFunc for uintptr-like types. If h is nil, a default hash.Hash64 implementation will be used.