Documentation ¶
Overview ¶
Package rthash exposes the various hash functions in runtime package.
The idea mainly comes from https://github.com/golang/go/issues/21195.
Index ¶
- type Hash
- func (h Hash) Bytes(x []byte) uintptr
- func (h Hash) Complex128(x complex128) uintptr
- func (h Hash) Complex64(x complex64) uintptr
- func (h Hash) Float32(x float32) uintptr
- func (h Hash) Float64(x float64) uintptr
- func (h Hash) Hash(x any) uintptr
- func (h Hash) Int(x int) uintptr
- func (h Hash) Int16(x int16) uintptr
- func (h Hash) Int32(x int32) uintptr
- func (h Hash) Int64(x int64) uintptr
- func (h Hash) Int8(x int8) uintptr
- func (h Hash) Interface(x any) uintptr
- func (h Hash) String(x string) uintptr
- func (h Hash) Uint(x uint) uintptr
- func (h Hash) Uint16(x uint16) uintptr
- func (h Hash) Uint32(x uint32) uintptr
- func (h Hash) Uint64(x uint64) uintptr
- func (h Hash) Uint8(x uint8) uintptr
- func (h Hash) Uintptr(x uintptr) uintptr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash exposes the various hash functions in runtime package. The idea mainly comes from https://github.com/golang/go/issues/21195.
See also: hash/maphash.Hash.
Unlike hash.Hash or hash/maphash.Hash, this Hash does not provide the ability to reset seed, the seed must be provided when creating the Hash instance and will be used during the lifetime.
This Hash type is intended to be used to do fast sharding, when implementing hash tables or other data structures, it's recommended to consider using hash/maphash.Hash as a proper choice.
The hash functions are not cryptographically secure. (See crypto/sha256 and crypto/sha512 for cryptographic use.)
A Hash must be initialized by calling New(). After initialized, a Hash is safe for concurrent use by multiple goroutines.
Each call to a same method with the same value will return the same result for a Hash instance, but it may and supposed to return different hash results from each Hash instance.
func New ¶
func New() Hash
New returns a new Hash instance, which exposes the various hash functions in runtime package. The returned Hash instance is safe for concurrent use by multiple goroutines.
func (Hash) Complex128 ¶
func (h Hash) Complex128(x complex128) uintptr
Complex128 exposes the c128hash function from runtime package.
func (Hash) Hash ¶
Hash returns a hash code for a comparable argument.
Note this function calls the hash functions for the concrete type if x is of type string, int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, uintptr, float32, float64, complex64, or complex128, else it calls
func (Hash) Int ¶
Int calculates hash of x using either int32Hash or int64Hash according to the pointer size of the platform.
func (Hash) Uint ¶
Uint calculates hash of x using either int32Hash or int64Hash according the pointer size of the platform.