Documentation ¶
Index ¶
- Constants
- func Hash(data []byte) uint64
- type ConsistentHash
- type Func
- type HashRing
- func (h *HashRing) Add(node any)
- func (h *HashRing) AddWithReplicas(node any, replicas int)
- func (h *HashRing) AddWithWeight(node any, weight int)
- func (h *HashRing) Get(v any) (any, bool)
- func (h *HashRing) GetAllNodes() []any
- func (h *HashRing) GetNodesCount() int
- func (h *HashRing) Remove(node any)
Constants ¶
const (
// TopWeight is the top weight that one entry might set.
TopWeight = 100
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConsistentHash ¶
type HashRing ¶
type HashRing struct {
// contains filtered or unexported fields
}
A HashRing is implementation of consistent hash.
func NewCustomHashRing ¶
NewCustomHashRing returns a HashRing with given replicas and hash func.
func (*HashRing) Add ¶
Add adds the node with the number of h.replicas, the later call will overwrite the replicas of the former calls.
func (*HashRing) AddWithReplicas ¶
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 (*HashRing) AddWithWeight ¶
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 (*HashRing) GetAllNodes ¶
GetAllNodes returns all nodes used in hash ring
return a slice with a string representation of the nodes
func (*HashRing) GetNodesCount ¶
GetNodesCount returns the current number of nodes