wyhash

package module
v0.0.0-...-35ce512 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Unlicense Imports: 6 Imported by: 1

README

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

Bytes Rate
0 0.49 ns/op
1-3 3.46 ns/op (0.29 GB/s - 0.88 GB/s)
4-8 3.40 ns/op (1.17 GB/s - 2.38 GB/s)
9-16 3.64 ns/op (2.47 GB/s - 4.39 GB/s)
17-32 4.63 ns/op (3.68 GB/s - 6.11 GB/s)
33-64 7.51 ns/op (4.40 GB/s - 7.98 GB/s)
65-96 9.22 ns/op (7.05 GB/s - 9.98 GB/s)
97-128 10.7 ns/op (9.03 GB/s - 11.3 GB/s)
240 17.5 ns/op (13.7 GB/s)
512 37.3 ns/op (13.7 GB/s)
1024 69.0 ns/op (14.8 GB/s)
100KB 6059 ns/op (16.9 GB/s)

RNG Benchmarks

Method Speed
Uint64 1.31 ns/op
Uint64n(large) 12.7 ns/op
Uint64n(med) 2.40 ns/op
Uint64n(small) 2.43 ns/op
Float64 2.17 ns/op

SRNG Benchmarks

Method Speed
Uint64 12.11 ns/op
Uint64n(large) 35.72 ns/op
Uint64n(med) 14.10 ns/op
Uint64n(small) 14.06 ns/op
Float64 16.75 ns/op

RNG with Mutex Benchmarks

Method Speed
Uint64 15.69 ns/op
Uint64n(large) 21.07 ns/op
Uint64n(med) 15.64 ns/op
Uint64n(small) 15.68 ns/op
Float64 15.74 ns/op

Read Concurrently(64 Bytes)

Method Speed
Go Math/rand Read 493.4 ns/op
RNG With Mutex Read 337.1 ns/op
SRNG Read 294.6 ns/op

Read No Race (64 Bytes)

Method Speed
Go Math/rand Read 76.71 ns/op
RNG Read 32.39 ns/op
SRNG Read 79.68 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 Read

func Read(b []byte) int

func ReadN

func ReadN(b []byte, min, max int) int

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.

Types

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 positive 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) Read

func (r *RNG) Read(b []byte) (i int)

func (*RNG) ReadN

func (r *RNG) ReadN(b []byte, min, max int) (i int)

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.

type SRNG

type SRNG uint64

SRNG is a thread-safe random number generator. The zero value is valid.

func (*SRNG) Float64

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

Float64 returns a float64 uniformly in [0, 1).

func (*SRNG) Int

func (r *SRNG) Int() int

Int returns a random positive int.

func (*SRNG) Intn

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

Intn returns an int uniformly in [0, n).

func (*SRNG) Read

func (r *SRNG) Read(b []byte) (i int)

func (*SRNG) ReadN

func (r *SRNG) ReadN(b []byte, min, max int) (i int)

func (*SRNG) Uint64

func (r *SRNG) Uint64() uint64

Uint64 returns a random uint64.

func (*SRNG) Uint64n

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

Uint64n returns a uint64 uniformly in [0, n).

Jump to

Keyboard shortcuts

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