wyhash

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 5 Imported by: 6

README

wyhash

A Go implementation of the 64-bit wyhash algorithm with a lot of optimizations. (final version 1)

original C++ implementation: https://github.com/wangyi-fudan/wyhash

QuickStart

package main

import "github.com/zhangyunhao116/wyhash"

func main() {
	println(wyhash.Sum64String("hello world!"))
}

Benchmark

Go version: go1.15.6 linux/amd64

CPU: AMD 3700x(8C16T), running at 3.6GHz

OS: ubuntu 18.04

MEMORY: 16G x 2 (3200MHz)

name              time/op
Wyhash/0-16         3.08ns ± 0%
Wyhash/1-16         4.09ns ± 0%
Wyhash/2-16         4.09ns ± 0%
Wyhash/3-16         4.09ns ± 1%
Wyhash/4-16         3.29ns ± 2%
Wyhash/5-16         3.71ns ± 1%
Wyhash/6-16         3.71ns ± 0%
Wyhash/7-16         3.76ns ± 3%
Wyhash/8-16         3.39ns ± 2%
Wyhash/9-16         3.78ns ± 2%
Wyhash/10-16        3.76ns ± 0%
Wyhash/11-16        3.76ns ± 0%
Wyhash/12-16        3.78ns ± 1%
Wyhash/13-16        3.76ns ± 1%
Wyhash/14-16        3.79ns ± 2%
Wyhash/15-16        3.77ns ± 0%
Wyhash/16-16        3.76ns ± 0%
Wyhash/17-16        4.98ns ± 0%
Wyhash/21-16        4.79ns ± 0%
Wyhash/24-16        4.39ns ± 2%
Wyhash/29-16        4.81ns ± 1%
Wyhash/32-16        4.77ns ± 0%
Wyhash/33-16        6.04ns ± 0%
Wyhash/64-16        7.25ns ± 1%
Wyhash/69-16        7.33ns ± 0%
Wyhash/96-16        8.31ns ± 0%
Wyhash/97-16        9.19ns ± 0%
Wyhash/128-16       10.4ns ± 0%
Wyhash/129-16       10.2ns ± 0%
Wyhash/240-16       15.7ns ± 3%
Wyhash/241-16       16.7ns ± 1%
Wyhash/512-16       28.2ns ± 1%
Wyhash/1024-16      50.2ns ± 1%
Wyhash/102400-16    4.27µs ± 0%

name              speed
Wyhash/0-16
Wyhash/1-16        245MB/s ± 0%
Wyhash/2-16        489MB/s ± 0%
Wyhash/3-16        733MB/s ± 1%
Wyhash/4-16       1.22GB/s ± 2%
Wyhash/5-16       1.35GB/s ± 1%
Wyhash/6-16       1.62GB/s ± 0%
Wyhash/7-16       1.86GB/s ± 3%
Wyhash/8-16       2.36GB/s ± 2%
Wyhash/9-16       2.39GB/s ± 0%
Wyhash/10-16      2.66GB/s ± 0%
Wyhash/11-16      2.92GB/s ± 0%
Wyhash/12-16      3.17GB/s ± 1%
Wyhash/13-16      3.45GB/s ± 0%
Wyhash/14-16      3.69GB/s ± 2%
Wyhash/15-16      3.99GB/s ± 0%
Wyhash/16-16      4.26GB/s ± 0%
Wyhash/17-16      3.41GB/s ± 0%
Wyhash/21-16      4.39GB/s ± 0%
Wyhash/24-16      5.46GB/s ± 2%
Wyhash/29-16      6.03GB/s ± 1%
Wyhash/32-16      6.72GB/s ± 0%
Wyhash/33-16      5.47GB/s ± 0%
Wyhash/64-16      8.83GB/s ± 1%
Wyhash/69-16      9.42GB/s ± 0%
Wyhash/96-16      11.6GB/s ± 0%
Wyhash/97-16      10.6GB/s ± 0%
Wyhash/128-16     12.3GB/s ± 0%
Wyhash/129-16     12.6GB/s ± 0%
Wyhash/240-16     15.3GB/s ± 2%
Wyhash/241-16     14.5GB/s ± 1%
Wyhash/512-16     18.1GB/s ± 1%
Wyhash/1024-16    20.4GB/s ± 1%
Wyhash/102400-16  24.0GB/s ± 0%

Documentation

Overview

Package wyhash implements https://github.com/wangyi-fudan/wyhash/blob/master/wyhash_final1.h

Index

Constants

View Source
const (
	DefaultSeed = 0xa0761d6478bd642f // s0

)

Variables

This section is empty.

Functions

func Sum64 added in v0.2.0

func Sum64(data []byte) uint64

func Sum64String added in v0.2.0

func Sum64String(data string) uint64

func Sum64StringWithSeed added in v0.3.0

func Sum64StringWithSeed(data string, seed uint64) uint64

func Sum64WithSeed added in v0.3.0

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

Types

type Digest added in v0.3.0

type Digest struct {
	// contains filtered or unexported fields
}

func New added in v0.3.0

func New(seed uint64) *Digest

New creates a new Digest that computes the 64-bit wyhash algorithm.

func NewDefault added in v0.3.0

func NewDefault() *Digest

func (*Digest) BlockSize added in v0.3.0

func (d *Digest) BlockSize() int

BlockSize always returns 64 bytes.

func (*Digest) InitSeed added in v0.3.0

func (d *Digest) InitSeed() uint64

func (*Digest) Reset added in v0.3.0

func (d *Digest) Reset()

Reset the digest, and the seed will be reset to initseed. The initseed is the seed when digest has been created.

func (*Digest) Seed added in v0.3.0

func (d *Digest) Seed() uint64

func (*Digest) SetInitSeed added in v0.3.0

func (d *Digest) SetInitSeed(seed uint64)

func (*Digest) SetSeed added in v0.3.0

func (d *Digest) SetSeed(seed uint64)

func (*Digest) Size added in v0.3.0

func (d *Digest) Size() int

Size always returns 8 bytes.

func (*Digest) Sum added in v0.3.0

func (d *Digest) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice.

func (*Digest) Sum64 added in v0.3.0

func (d *Digest) Sum64() uint64

Sum64 returns the current hash.

func (*Digest) Write added in v0.3.0

func (d *Digest) Write(input []byte) (int, error)

Write (via the embedded io.Writer interface) adds more data to the running hash. It never returns an error.

Directories

Path Synopsis
internal
wyhashfv1
Package wyhashfv1 implements https://github.com/wangyi-fudan/wyhash/blob/master/wyhash_final1.h DO NOT USE IT, for test only.
Package wyhashfv1 implements https://github.com/wangyi-fudan/wyhash/blob/master/wyhash_final1.h DO NOT USE IT, for test only.

Jump to

Keyboard shortcuts

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