Home

Awesome

wyhash

GoDoc Sourcegraph Go Report Card

This package is a port of the wyhash library v3 to Go.


Hash Benchmarks

Run on my i7-6700K CPU @ 4.00GHz

BytesRate
00.49 ns/op
1-33.46 ns/op (0.29 GB/s - 0.88 GB/s)
4-83.40 ns/op (1.17 GB/s - 2.38 GB/s)
9-163.64 ns/op (2.47 GB/s - 4.39 GB/s)
17-324.63 ns/op (3.68 GB/s - 6.11 GB/s)
33-647.51 ns/op (4.40 GB/s - 7.98 GB/s)
65-969.22 ns/op (7.05 GB/s - 9.98 GB/s)
97-12810.7 ns/op (9.03 GB/s - 11.3 GB/s)
24017.5 ns/op (13.7 GB/s)
51237.3 ns/op (13.7 GB/s)
102469.0 ns/op (14.8 GB/s)
100KB6059 ns/op (16.9 GB/s)

RNG Benchmarks

MethodSpeed
Uint641.31 ns/op
Uint64n(large)12.7 ns/op
Uint64n(med)2.40 ns/op
Uint64n(small)2.43 ns/op
Float642.17 ns/op

Usage

func Float64

func Float64() float64

Float64 returns a float64 uniformly in [0, 1). Safe for concurrent callers.

func Hash

func Hash(data []byte, seed uint64) uint64

Hash returns a 64bit digest of the data with different ones for every seed.

func HashString

func HashString(data string, seed uint64) uint64

HashString returns a 64bit digest of the data with different ones for every seed.

func Int

func Int() int

Int returns a random int. Safe for concurrent callers.

func Intn

func Intn(n int) int

Intn returns a int uniformly in [0, n). Safe for concurrent callers.

func Uint64

func Uint64() uint64

Uint64 returns a random uint64. Safe for concurrent callers.

func Uint64n

func Uint64n(n uint64) uint64

Uint64n returns a uint64 uniformly in [0, n). Safe for concurrent callers.

type RNG

type RNG uint64

RNG is a random number generator. The zero value is valid.

func (*RNG) Float64

func (r *RNG) Float64() (v float64)

Float64 returns a float64 uniformly in [0, 1). Not safe for concurrent callers.

func (*RNG) Int

func (r *RNG) Int() int

Int returns a random int. Not safe for concurrent callers.

func (*RNG) Intn

func (r *RNG) Intn(n int) int

Intn returns an int uniformly in [0, n). Not safe for concurrent callers.

func (*RNG) Uint64

func (r *RNG) Uint64() uint64

Uint64 returns a random uint64. Not safe for concurrent callers.

func (*RNG) Uint64n

func (r *RNG) Uint64n(n uint64) uint64

Uint64n returns a uint64 uniformly in [0, n). Not safe for concurrent callers.