city – github.com/go-faster/city Index | Examples | Files

package city

import "github.com/go-faster/city"

Package city implements CityHash in go.

Index

Examples

Functions

func CH64

func CH64(s []byte) uint64

CH64 returns ClickHouse version of Hash64.

func Hash32

func Hash32(s []byte) uint32

Hash32 return 32-bit hash.

Example

Code:play 

package main

import (
	"fmt"

	"github.com/go-faster/city"
)

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

}

Output:

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

func Hash64

func Hash64(s []byte) uint64

Hash64 return a 64-bit hash.

Example

Code:play 

package main

import (
	"fmt"

	"github.com/go-faster/city"
)

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

}

Output:

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

func Hash64WithSeed

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

Hash64WithSeed return a 64-bit hash with a seed.

func Hash64WithSeeds

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

Hash64WithSeeds return a 64-bit hash with two seeds.

Types

type U128

type U128 struct {
	Low  uint64 // first 32 bits
	High uint64 // last 32 bits

}

U128 is uint128.

func Hash128

func Hash128(s []byte) U128

Hash128 returns 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 Hash64() on sufficiently long strings. It's slower than necessary on shorter strings, but we expect that case to be relatively unimportant.

Example

Code:play 

package main

import (
	"fmt"

	"github.com/go-faster/city"
)

func main() {
	fmt.Println(city.Hash128([]byte("hello")))

}

Output:

6f72e4abb491a74a65148f580b45f347

func Hash128Seed

func Hash128Seed(s []byte, seed U128) U128

Hash128Seed return a 128-bit hash with a seed.

func (U128) Append

func (u U128) Append(buf []byte) []byte

Append appends uint128 big value to buf in big endian.

Append is much faster that appending Arr result.

func (U128) Arr

func (u U128) Arr() (v [16]byte)

Arr returns byte array that represents uint128 value of U128 in big endian.

func (U128) String

func (u U128) String() string

Source Files

128.go 32.go 64.go ch_64.go doc.go

Version
v0.2.0
Published
Nov 17, 2021
Platform
js/wasm
Imports
2 packages
Last checked
now

Tools for package owners.