xhash

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: Apache-2.0 Imports: 4 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(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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sum128

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

Sum128 run murmur3.Sum128

func Sum128String

func Sum128String(str string) (uint64, uint64)

Sum128String run murmur3.Sum128

func Sum32

func Sum32(data []byte) uint32

Sum32 run crc32.ChecksumIEEE returns the CRC-32 checksum of data using the IEEE polynomial.

func Sum32String

func Sum32String(str string) uint32

Sum32String run crc32.ChecksumIEEE returns the CRC-32 checksum of data using the IEEE polynomial.

func Sum64

func Sum64(data []byte) uint64

Sum64 run crc64.Checksum returns the CRC-64 checksum of data using the ECMA polynomial.

func Sum64String

func Sum64String(str string) uint64

Sum64String run crc64.Checksum returns the CRC-64 checksum of data using the ECMA polynomial.

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
maphash
Package maphash provides hash functions on byte sequences.
Package maphash provides hash functions on byte sequences.

Jump to

Keyboard shortcuts

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