Documentation ¶
Index ¶
Constants ¶
View Source
const (
TopWeight = 100
)
Variables ¶
This section is empty.
Functions ¶
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) 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顺时针找到最近的虚拟节点 再通过虚拟节点找到真实节点
type VirtualNode ¶
type VirtualNode = uint64
Click to show internal directories.
Click to hide internal directories.