consistenthash

package
v0.0.0-...-a2093d6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: LGPL-2.1 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TopWeight = 100
)

Variables

This section is empty.

Functions

func Hash

func Hash(data []byte) uint64

Hash returns the hash value of data.

Types

type ConsistentHash

type ConsistentHash struct {
	// contains filtered or unexported fields
}

一致性hash结构体

func NewConsistentHash

func NewConsistentHash() *ConsistentHash

func NewCustomConsistentHash

func NewCustomConsistentHash(replicas int, fn HashFunc) *ConsistentHash

func (*ConsistentHash) Add

func (h *ConsistentHash) Add(node HashNode)

添加一个node

func (*ConsistentHash) AddWithReplicas

func (h *ConsistentHash) AddWithReplicas(node HashNode, replicas int)

扩容操作,增加物理节点

func (*ConsistentHash) AddWithWeight

func (h *ConsistentHash) AddWithWeight(node HashNode, weight int)

按照权重来控制虚拟节点的个数 权重越高,虚拟节点数量越多

func (*ConsistentHash) Get

func (h *ConsistentHash) Get(v interface{}) (HashNode, bool)

根据v顺时针找到最近的虚拟节点 再通过虚拟节点找到真实节点

func (*ConsistentHash) Remove

func (h *ConsistentHash) Remove(node HashNode)

删除物理节点 所对应的虚拟节点一起删除

type HashFunc

type HashFunc func(data []byte) uint64

PlaceholderType = struct{} 哈希函数

type HashNode

type HashNode = interface{}

type NodeRepr

type NodeRepr = string

type VirtualNode

type VirtualNode = uint64

Jump to

Keyboard shortcuts

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