Documentation ¶
Index ¶
Constants ¶
const (
// TopWeight is the top weight that one entry might set.
TopWeight = 100
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
A ConsistentHash is a ring hash implementation.
func NewConsistentHash ¶
func NewConsistentHash() *ConsistentHash
NewConsistentHash returns a ConsistentHash.
func NewCustomConsistentHash ¶
func NewCustomConsistentHash(replicas int, fn Func) *ConsistentHash
NewCustomConsistentHash returns a ConsistentHash with given replicas and hash func.
func (*ConsistentHash) Add ¶
func (h *ConsistentHash) Add(node any)
Add adds the node with the number of h.replicas, the later call will overwrite the replicas of the former calls.
func (*ConsistentHash) AddWithReplicas ¶
func (h *ConsistentHash) AddWithReplicas(node any, replicas int)
AddWithReplicas adds the node with the number of replicas, replicas will be truncated to h.replicas if it's larger than h.replicas, the later call will overwrite the replicas of the former calls.
func (*ConsistentHash) AddWithWeight ¶
func (h *ConsistentHash) AddWithWeight(node any, weight int)
AddWithWeight adds the node with weight, the weight can be 1 to 100, indicates the percent, the later call will overwrite the replicas of the former calls.
func (*ConsistentHash) Get ¶
func (h *ConsistentHash) Get(v any) (any, bool)
Get returns the corresponding node from h base on the given v.
func (*ConsistentHash) Remove ¶
func (h *ConsistentHash) Remove(node any)
Remove removes the given node from h.