rthash

package
v2.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: MIT Imports: 2 Imported by: 0

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

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) Bytes

func (h Hash) Bytes(x []byte) uintptr

Bytes exposes the bytesHash function from runtime package.

func (Hash) Complex128

func (h Hash) Complex128(x complex128) uintptr

Complex128 exposes the c128hash function from runtime package.

func (Hash) Complex64

func (h Hash) Complex64(x complex64) uintptr

Complex64 exposes the c64hash function from runtime package.

func (Hash) Float32

func (h Hash) Float32(x float32) uintptr

Float32 exposes the f32hash function from runtime package.

func (Hash) Float64

func (h Hash) Float64(x float64) uintptr

Float64 exposes the f64hash function from runtime package.

func (Hash) Hash

func (h Hash) Hash(x interface{}) uintptr

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

func (h Hash) Int(x int) uintptr

Int calculates hash of x using either int32Hash or int64Hash according to the pointer size of the platform.

func (Hash) Int16

func (h Hash) Int16(x int16) uintptr

Int16 exposes the memhash16 function from runtime package.

func (Hash) Int32

func (h Hash) Int32(x int32) uintptr

Int32 exposes the int32Hash function from runtime package.

func (Hash) Int64

func (h Hash) Int64(x int64) uintptr

Int64 exposes the int64Hash function from runtime package.

func (Hash) Int8

func (h Hash) Int8(x int8) uintptr

Int8 exposes the memhash8 function from runtime package.

func (Hash) Interface

func (h Hash) Interface(x interface{}) uintptr

Interface exposes the efaceHash function from runtime package.

func (Hash) String

func (h Hash) String(x string) uintptr

String exposes the stringHash function from runtime package.

func (Hash) Uint

func (h Hash) Uint(x uint) uintptr

Uint calculates hash of x using either int32Hash or int64Hash according the pointer size of the platform.

func (Hash) Uint16

func (h Hash) Uint16(x uint16) uintptr

Uint16 exposes the memhash16 function from runtime package.

func (Hash) Uint32

func (h Hash) Uint32(x uint32) uintptr

Uint32 exposes the int32Hash function from runtime package.

func (Hash) Uint64

func (h Hash) Uint64(x uint64) uintptr

Uint64 exposes the int64Hash function from runtime package.

func (Hash) Uint8

func (h Hash) Uint8(x uint8) uintptr

Uint8 exposes the memhash8 function from runtime package.

func (Hash) Uintptr

func (h Hash) Uintptr(x uintptr) uintptr

Uintptr calculates hash of x using either int32Hash or int64Hash according to the pointer size of the platform.

Jump to

Keyboard shortcuts

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