xxhash

package
v0.0.0-...-eaf2392 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2015 License: MIT Imports: 5 Imported by: 0

README

xxhash GoDoc Build Status

--

xxhash (Copyright (c) 2012-2014, Yann Collet) is an extremely fast non-cryptographic Hash algorithm, working at speeds close to RAM limits.

Supports both the 32bit and 64bit versions of the the algorithm.

Install

Install the recommended pure-go version (much faster with shorter input):

go get github.com/OneOfOne/xxhash/native

Or to install the CGO wrapper over the original C code (only recommended if hashing huge slices at a time):

go get github.com/OneOfOne/xxhash

Features

  • The native version is optimized and is as you can get in pure Go.
  • The native version falls back to a less optimized version on appengine (it uses unsafe).
  • The native version (on non-appengine builds) by default ignores endianness, if you require endianness safety (aka same hash on big and little endian systems), build with -tags be.
  • Both the native version and the cgo version supports 64bit and 32bit versions of the algorithm.
  • When using the cgo version, it will automaticly fallback to the native version if cgo isn't available.

Benchmark

go test github.com/OneOfOne/xxhash -bench=. -benchmem
Core i7-4790 @ 3.60GHz, Linux 3.16.2 (64bit)
BenchmarkXxhash32                1000000              1029 ns/op               0 B/op          0 allocs/op
BenchmarkXxhash32Cgo             3000000               456 ns/op               0 B/op          0 allocs/op

BenchmarkXxhash64                2000000               727 ns/op               0 B/op          0 allocs/op
BenchmarkXxhash64Cgo             5000000               328 ns/op               0 B/op          0 allocs/op

BenchmarkFnv32                   300000               4930 ns/op            2816 B/op          1 allocs/op
BenchmarkFnv64                   300000               4994 ns/op            2816 B/op          1 allocs/op
BenchmarkAdler32                 1000000              1238 ns/op               0 B/op          0 allocs/op
BenchmarkCRC32IEEE               300000               5087 ns/op               0 B/op          0 allocs/op

# key = []byte("Test-key-100")
BenchmarkXxhash64VeryShort       100000000            16.8 ns/op             0 B/op          0 allocs/op
BenchmarkXxhash64CgoVeryShort    10000000              174 ns/op               0 B/op          0 allocs/op

# MultiWrites uses h.Write multiple times
BenchmarkXxhash64MultiWrites     2000000               815 ns/op               0 B/op          0 allocs/op
BenchmarkXxhash64CgoMultiWrites  5000000               342 ns/op               0 B/op          0 allocs/op

Usage

h := xxhash.New64()
// r, err := os.Open("......")
// defer f.Close()
r := strings.NewReader(F)
io.Copy(h, r)
fmt.Println("xxhash.Backend:", xxhash.Backend)
fmt.Println("File checksum:", h.Sum64())

playground

License

Apache v2.0

Copyright 2014 OneOfOne

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

View Source
const Backend = "CGO"

Backend returns the current version of xxhash being used.

Variables

View Source
var (
	// ErrAlreadyComputed is returned if you try to call Write after calling Sum
	ErrAlreadyComputed = errors.New("cannot update an already computed hash")
	// ErrMemoryLimit is returned if you try to call Write with more than 1 Gigabytes of data
	ErrMemoryLimit = errors.New("cannot use more than 1 Gigabytes of data at once")
)

Functions

func Checksum32

func Checksum32(in []byte) uint32

Checksum32 returns the checksum of the input data with the seed set to 0

func Checksum32S

func Checksum32S(in []byte, seed uint32) uint32

Checksum32S returns the checksum of the input bytes with the specific seed.

func Checksum64

func Checksum64(in []byte) uint64

Checksum64 returns the checksum of the input data with the seed set to 0

func Checksum64S

func Checksum64S(in []byte, seed uint64) uint64

Checksum64S returns the checksum of the input bytes with the specific seed.

func New32

func New32() hash.Hash32

New32 creates a new hash.Hash32 computing the 32bit xxHash checksum starting with the seed set to 0x0.

func New64

func New64() hash.Hash64

New64 creates a new hash.Hash64 computing the 64bit xxHash checksum starting with the seed set to 0x0.

func NewS32

func NewS32(seed uint32) hash.Hash32

NewS32 creates a new hash.Hash32 computing the 32bit xxHash checksum starting with the specific seed.

func NewS64

func NewS64(seed uint64) hash.Hash64

NewS64 creates a new hash.Hash64 computing the 64bit xxHash checksum starting with the specific seed.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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