hash

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2025 License: ISC Imports: 3 Imported by: 0

README

Hash

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashFunc

type HashFunc[T any] func(T) uint64

HashFunc defines a generic function type for hashing a key of type K.

func HashFuncForBool

func HashFuncForBool[T ~bool](h hash.Hash64) HashFunc[T]

HashFuncForBool creates a HashFunc for boolean-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForBoolSlice

func HashFuncForBoolSlice[T ~[]bool](h hash.Hash64) HashFunc[T]

HashFuncForBoolSlice creates a HashFunc for slice types with boolean elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForComplex64

func HashFuncForComplex64[T ~complex64](h hash.Hash64) HashFunc[T]

HashFuncForComplex64 creates a HashFunc for complex64-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForComplex64Slice

func HashFuncForComplex64Slice[T ~[]complex64](h hash.Hash64) HashFunc[T]

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

func HashFuncForFloat32[T ~float32](h hash.Hash64) HashFunc[T]

HashFuncForFloat32 creates a HashFunc for float32-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForFloat32Slice

func HashFuncForFloat32Slice[T ~[]float32](h hash.Hash64) HashFunc[T]

HashFuncForFloat32Slice creates a HashFunc for slice types with float32 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForFloat64

func HashFuncForFloat64[T ~float64](h hash.Hash64) HashFunc[T]

HashFuncForFloat64 creates a HashFunc for float64-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForFloat64Slice

func HashFuncForFloat64Slice[T ~[]float64](h hash.Hash64) HashFunc[T]

HashFuncForFloat64Slice creates a HashFunc for slice types with float64 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt

func HashFuncForInt[T ~int](h hash.Hash64) HashFunc[T]

HashFuncForInt creates a HashFunc for int-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt8

func HashFuncForInt8[T ~int8](h hash.Hash64) HashFunc[T]

HashFuncForInt8 creates a HashFunc for int8-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt8Slice

func HashFuncForInt8Slice[T ~[]int8](h hash.Hash64) HashFunc[T]

HashFuncForInt8Slice creates a HashFunc for slice types with int8 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt16

func HashFuncForInt16[T ~int16](h hash.Hash64) HashFunc[T]

HashFuncForInt16 creates a HashFunc for int16-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt16Slice

func HashFuncForInt16Slice[T ~[]int16](h hash.Hash64) HashFunc[T]

HashFuncForInt16Slice creates a HashFunc for slice types with int16 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt32

func HashFuncForInt32[T ~int32](h hash.Hash64) HashFunc[T]

HashFuncForInt32 creates a HashFunc for int32-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt32Slice

func HashFuncForInt32Slice[T ~[]int32](h hash.Hash64) HashFunc[T]

HashFuncForInt32Slice creates a HashFunc for slice types with int32 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt64

func HashFuncForInt64[T ~int64](h hash.Hash64) HashFunc[T]

HashFuncForInt64 creates a HashFunc for int64-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForInt64Slice

func HashFuncForInt64Slice[T ~[]int64](h hash.Hash64) HashFunc[T]

HashFuncForInt64Slice creates a HashFunc for slice types with int64 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForIntSlice

func HashFuncForIntSlice[T ~[]int](h hash.Hash64) HashFunc[T]

HashFuncForIntSlice creates a HashFunc for slice types with int elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForString

func HashFuncForString[T ~string](h hash.Hash64) HashFunc[T]

HashFuncForString creates a HashFunc for string-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForStringSlice

func HashFuncForStringSlice[T ~[]string](h hash.Hash64) HashFunc[T]

HashFuncForStringSlice creates a HashFunc for slice types with string elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint

func HashFuncForUint[T ~uint](h hash.Hash64) HashFunc[T]

HashFuncForUint creates a HashFunc for uint-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint8

func HashFuncForUint8[T ~uint8](h hash.Hash64) HashFunc[T]

HashFuncForUint8 creates a HashFunc for uint8-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint8Slice

func HashFuncForUint8Slice[T ~[]uint8](h hash.Hash64) HashFunc[T]

HashFuncForUint8Slice creates a HashFunc for slice types with uint8 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint16

func HashFuncForUint16[T ~uint16](h hash.Hash64) HashFunc[T]

HashFuncForUint16 creates a HashFunc for uint16-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint16Slice

func HashFuncForUint16Slice[T ~[]uint16](h hash.Hash64) HashFunc[T]

HashFuncForUint16Slice creates a HashFunc for slice types with uint16 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint32

func HashFuncForUint32[T ~uint32](h hash.Hash64) HashFunc[T]

HashFuncForUint32 creates a HashFunc for uint32-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint32Slice

func HashFuncForUint32Slice[T ~[]uint32](h hash.Hash64) HashFunc[T]

HashFuncForUint32Slice creates a HashFunc for slice types with uint32 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint64

func HashFuncForUint64[T ~uint64](h hash.Hash64) HashFunc[T]

HashFuncForUint64 creates a HashFunc for uint64-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUint64Slice

func HashFuncForUint64Slice[T ~[]uint64](h hash.Hash64) HashFunc[T]

HashFuncForUint64Slice creates a HashFunc for slice types with uint64 elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUintSlice

func HashFuncForUintSlice[T ~[]uint](h hash.Hash64) HashFunc[T]

HashFuncForUintSlice creates a HashFunc for slice types with uint elements. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUintptr

func HashFuncForUintptr[T ~uintptr](h hash.Hash64) HashFunc[T]

HashFuncForUintptr creates a HashFunc for uintptr-like types. If h is nil, a default hash.Hash64 implementation will be used.

func HashFuncForUintptrSlice

func HashFuncForUintptrSlice[T ~[]uintptr](h hash.Hash64) HashFunc[T]

HashFuncForUintptrSlice creates a HashFunc for slice types with uintptr elements. If h is nil, a default hash.Hash64 implementation will be used.

type Hasher added in v0.10.3

type Hasher interface {
	Hash() uint64
}

Hasher is a generic interface that defines a method for computing a hash value for any type T.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL