Help us shape the future of Go! Take the 2026 Go Developer Survey

consistent

package
v1.12.9 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash[T INode] struct {
	// contains filtered or unexported fields
}

Hash 一致性哈希实现

func NewHash

func NewHash[T INode](virtuals int) *Hash[T]

NewHash 创建一致性哈希实例

func (*Hash[T]) AddNode

func (ch *Hash[T]) AddNode(node T) error

AddNode 添加节点

func (*Hash[T]) Clear

func (ch *Hash[T]) Clear()

Clear 清空所有节点

func (*Hash[T]) GetNode

func (ch *Hash[T]) GetNode(key string) T

GetNode 根据key获取对应的节点

func (*Hash[T]) GetNodeByID

func (ch *Hash[T]) GetNodeByID(nodeID uint32) T

GetNodeByID 根据节点ID获取节点

func (*Hash[T]) GetNodeByUint64

func (ch *Hash[T]) GetNodeByUint64(key uint64) T

GetNodeByUint64 根据uint64类型的key获取节点

func (*Hash[T]) GetNodeCount

func (ch *Hash[T]) GetNodeCount() int

GetNodeCount 获取节点数量

func (*Hash[T]) GetNodes

func (ch *Hash[T]) GetNodes() []T

GetNodes 获取所有节点

func (*Hash[T]) GetNodesForKey

func (ch *Hash[T]) GetNodesForKey(key string, count int) []T

GetNodesForKey 获取某个key的所有备份节点(用于故障转移)

func (*Hash[T]) GetVirtualNodeCount

func (ch *Hash[T]) GetVirtualNodeCount() int

GetVirtualNodeCount 获取虚拟节点数量

func (*Hash[T]) RemoveNode

func (ch *Hash[T]) RemoveNode(nodeID uint32) T

RemoveNode 移除节点

func (*Hash[T]) UpdateNode

func (ch *Hash[T]) UpdateNode(node T) error

UpdateNode 更新节点信息

type INode

type INode interface {
	GetId() uint32
}

Jump to

Keyboard shortcuts

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