murmur3

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: BSD-3-Clause Imports: 2 Imported by: 1

README

stackmurmur3

Note: This is a fork of github.com/spaolacci/murmur3 that provides digests that are allocated on the stack and can be incrementally written to. This is useful for places where you perform concurrent hashing and there's no good place to cache a hash without needing to acquire it expensively (under lock, etc).

Build Status

Native Go implementation of Austin Appleby's third MurmurHash revision (aka MurmurHash3).

Reference algorithm has been slightly hacked as to support the streaming mode required by Go's standard Hash interface.

Benchmarks

This shows that its really only useful to use this stack version when allocating per operation is too expensive (i.e. GC already the limiting factor).


Benchmark_Incremental_Origin_128_1-4       20000000      80.4 ns/op      12.43 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_2-4       20000000      89.5 ns/op      22.35 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_4-4       20000000     106 ns/op        37.72 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_8-4       10000000     108 ns/op        73.65 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_16-4      20000000     110 ns/op       144.97 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_32-4      20000000     102 ns/op      1253.59 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_64-4      20000000    88.3 ns/op       725.15 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_128-4     20000000     104 ns/op      1230.40 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_256-4     10000000     141 ns/op      1806.16 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_512-4     10000000     177 ns/op      2882.86 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_1024-4     5000000     317 ns/op      3226.23 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_2048-4     3000000     495 ns/op      4133.69 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_4096-4     2000000     876 ns/op      4673.40 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Origin_128_8192-4     1000000    1719 ns/op      4763.41 MB/s    16 B/op    1 allocs/op
Benchmark_Incremental_Forked_128_1-4       10000000     135 ns/op         7.36 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_2-4       10000000     160 ns/op        12.43 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_4-4       10000000     158 ns/op        25.19 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_8-4       10000000     152 ns/op        52.45 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_16-4      20000000     109 ns/op       145.64 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_32-4      10000000     131 ns/op       970.13 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_64-4      10000000     123 ns/op       517.18 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_128-4     10000000     151 ns/op       844.44 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_256-4     10000000     155 ns/op      1646.55 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_512-4     10000000     205 ns/op      2491.70 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_1024-4     5000000     305 ns/op      3346.95 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_2048-4     3000000     531 ns/op      3853.73 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_4096-4     2000000     908 ns/op      4506.57 MB/s     0 B/op    0 allocs/op
Benchmark_Incremental_Forked_128_8192-4     1000000    1711 ns/op      4785.81 MB/s     0 B/op    0 allocs/op

Documentation

Overview

Package murmur3 implements Austin Appleby's non-cryptographic MurmurHash3.

Reference implementation:
   http://code.google.com/p/smhasher/wiki/MurmurHash3

History, characteristics and (legacy) perfs:
   https://sites.google.com/site/murmurhash/
   https://sites.google.com/site/murmurhash/statistics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sum128

func Sum128(data []byte) (h1 uint64, h2 uint64)

Sum128 returns the MurmurHash3 sum of data without any heap allocations.

func Sum128WithSeed

func Sum128WithSeed(data []byte, seed uint32) (h1 uint64, h2 uint64)

Sum128WithSeed returns the MurmurHash3 sum of data given a seed without any heap allocations.

func Sum32

func Sum32(data []byte) uint32

Sum32 returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):

hasher := New32()
hasher.Write(data)
return hasher.Sum32()

func Sum32WithSeed

func Sum32WithSeed(data []byte, seed uint32) uint32

Sum32WithSeed returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):

hasher := New32WithSeed(seed)
hasher.Write(data)
return hasher.Sum32()

func Sum64

func Sum64(data []byte) uint64

Sum64 returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):

hasher := New64()
hasher.Write(data)
return hasher.Sum64()

func Sum64WithSeed

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

Sum64WithSeed returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):

hasher := New64WithSeed(seed)
hasher.Write(data)
return hasher.Sum64()

Types

type Digest128

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

Digest128 is a murmur3 128 bit digest that can be written to as many consequent times as necessary without heap allocations.

func New128

func New128() Digest128

New128 returns a new 128 bit digest.

func New128WithSeed

func New128WithSeed(seed uint32) Digest128

New128WithSeed returns a new 128 bit digest with a seed.

func (Digest128) BlockSize

func (d Digest128) BlockSize() int

func (Digest128) Size

func (d Digest128) Size() int

Size returns the number of bytes Sum will return.

func (Digest128) Sum

func (d Digest128) Sum(b []byte) []byte

Sum returns the current binary hash appended to input byte ref.

func (Digest128) Sum128

func (d Digest128) Sum128() (h1, h2 uint64)

Sum128 returns the 128 bit hash of the digest.

func (Digest128) Write

func (d Digest128) Write(p []byte) Digest128

Write will write bytes to the digest and return a new digest representing the derived digest.

type Digest32

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

Digest32 represents a partial evaluation of a 32 bits hash.

func New32

func New32() Digest32

New32 returns new 32-bit hasher

func New32WithSeed

func New32WithSeed(seed uint32) Digest32

New32WithSeed returns new 32-bit hasher set with explicit seed value

func (Digest32) BlockSize

func (d Digest32) BlockSize() int

func (Digest32) Size

func (d Digest32) Size() int

func (Digest32) Sum

func (d Digest32) Sum(b []byte) []byte

func (Digest32) Sum32

func (d Digest32) Sum32() (h1 uint32)

func (Digest32) Write

func (d Digest32) Write(p []byte) Digest32

Write will write bytes to the digest and return a new digest representing the derived digest.

type Digest64

type Digest64 Digest128

Digest64 is half a digest128.

func New64

func New64() Digest64

New64 returns a 64-bit hasher

func New64WithSeed

func New64WithSeed(seed uint32) Digest64

New64WithSeed returns a 64-bit hasher set with explicit seed value

func (Digest64) Size

func (d Digest64) Size() int

func (Digest64) Sum

func (d Digest64) Sum(b []byte) []byte

func (Digest64) Sum64

func (d Digest64) Sum64() uint64

func (Digest64) Write

func (d Digest64) Write(p []byte) Digest64

Jump to

Keyboard shortcuts

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