xhash

package
v0.0.0-...-f89cf20 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: MIT Imports: 5 Imported by: 0

README

XHash

提供了默认的Hash32, Hash64, Hash128的实现, 以及一致性哈希,以及进程内的string[]bytehash

Hash32(CRC)

package xhash

func Sum32(data []byte) uint32

func Sum32String(str string) uint32

Hash64(XXHASH)

package xhash

func Sum64(data []byte) uint64

func Sum64String(str string) uint64

Hash128(MURMUR3)

package xhash

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

func Sum128String(str string) (uint64, uint64)

一致性哈希

package ring

type Hash func(data []byte) uint32

type Map struct {
	hash     Hash
	replicas int
	keys     []int // Sorted
	hashMap  map[int]string
}

func New(replicas int, fn Hash) *Map

func (*Map) IsEmpty() bool // 判断hash环是否为空
func (*Map) Add(nodes ...string) // 加入节点
func (*Map) Remove(nodes ...string) // 删除节点
func (*Map) Get(key string) string // 根据key进行hash选取节点

Runtime Hash (标准库在1.14中会实现)

package runtime

func String(str string) uint64

func Bytes(data []byte) uint64

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDInt

func IDInt(id string) []int64

func IDString

func IDString(id string) string

func IntID

func IntID(ints []int64) string

func StringID

func StringID(hexStr string) string

func Sum128

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

func Sum128String

func Sum128String(str string) (uint64, uint64)

func Sum32

func Sum32(data []byte) uint32

func Sum32String

func Sum32String(str string) uint32

func Sum64

func Sum64(data []byte) uint64

func Sum64String

func Sum64String(str string) uint64

Types

type Hash128

type Hash128 interface {
	hash.Hash
	Sum128() (uint64, uint64)
}

type Hash32

type Hash32 = hash.Hash32

type Hash64

type Hash64 = hash.Hash64

Directories

Path Synopsis
internal
bytes
Package bytes/hash provides hash functions on byte sequences.
Package bytes/hash provides hash functions on byte sequences.

Jump to

Keyboard shortcuts

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