package
0.1.1
Repository: https://github.com/go-board/x-go.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

XHash

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

Hash32(CRC)

package xhash

func Sum32(data []byte) uint32

func Sum32String(str string) uint32

Hash64(CRC64)

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