cityhash

package module
v0.0.0-...-4c2731b Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 1 Imported by: 0

README

cityhash

Build Status codecov GitHub tag godoc

Google CityHash in Go.

CityHash provides hash functions for strings.

cityhash homepage

Example

import github.com/tenfyzhong/cityhash

func ExampleCityHash32() {
	s := []byte("hello")
	hash32 := cityhash.CityHash32(s)
	fmt.Printf("the 32-bit hash of 'hello' is: 0x%x\n", hash32)

	// Output:
	// the 32-bit hash of 'hello' is: 0x79969366
}

func ExampleCityHash64() {
	s := []byte("hello")
	hash64 := cityhash.CityHash64(s)
	fmt.Printf("the 64-bit hash of 'hello' is: 0x%x\n", hash64)

	// Output:
	// the 64-bit hash of 'hello' is: 0xb48be5a931380ce8
}

func ExampleCityHash128() {
	s := []byte("hello")
	hash128 := cityhash.CityHash128(s)
	fmt.Printf("the 128-bit hash of 'hello' is: 0x%x%x\n", hash128.High64(), hash128.Low64())

	// Output:
	// the 128-bit hash of 'hello' is: 0x65148f580b45f3476f72e4abb491a74a
}

Documentation

Overview

Package cityhash provides hash functions for strings. The functions mix the input bits thoroughly but are not suitable for cryptography. See "Hash Quality," below, for details on how CityHash was tested and so on.

All members of the CityHash family were designed with heavy reliance on previous work by Austin Appleby, Bob Jenkins, and others. For example, CityHash32 has many similarities with Murmur3a.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CityHash32

func CityHash32(s []byte) uint32

CityHash32 return 32-bit hash.

Example
s := []byte("hello")
hash32 := CityHash32(s)
fmt.Printf("the 32-bit hash of 'hello' is: 0x%x\n", hash32)
Output:

the 32-bit hash of 'hello' is: 0x79969366

func CityHash64

func CityHash64(s []byte) uint64

CityHash64 return a 64-bit hash.

Example
s := []byte("hello")
hash64 := CityHash64(s)
fmt.Printf("the 64-bit hash of 'hello' is: 0x%x\n", hash64)
Output:

the 64-bit hash of 'hello' is: 0xb48be5a931380ce8

func CityHash64WithSeed

func CityHash64WithSeed(s []byte, seed uint64) uint64

CityHash64WithSeed return a 64-bit hash with a seed.

func CityHash64WithSeeds

func CityHash64WithSeeds(s []byte, seed0, seed1 uint64) uint64

CityHash64WithSeeds return a 64-bit hash with two seeds.

Types

type Uint128

type Uint128 [2]uint64

Uint128 type uint128

func CityHash128

func CityHash128(s []byte) Uint128

CityHash128 return a 128-bit hash and are tuned for strings of at least a few hundred bytes. Depending on your compiler and hardware, it's likely faster than CityHash64() on sufficiently long strings. It's slower than necessary on shorter strings, but we expect that case to be relatively unimportant.

Example
s := []byte("hello")
hash128 := CityHash128(s)
fmt.Printf("the 128-bit hash of 'hello' is: 0x%x%x\n", hash128.High64(), hash128.Low64())
Output:

the 128-bit hash of 'hello' is: 0x65148f580b45f3476f72e4abb491a74a

func CityHash128WithSeed

func CityHash128WithSeed(s []byte, seed Uint128) Uint128

CityHash128WithSeed return a 128-bit hash with a seed.

func (Uint128) High64

func (u Uint128) High64() uint64

High64 return the high 64-bit of u.

func (Uint128) Low64

func (u Uint128) Low64() uint64

Low64 return the low 64-bit of u.

Jump to

Keyboard shortcuts

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