Documentation ¶
Index ¶
- type Hasher
- func (h *Hasher) AddMembers(members ...string)
- func (h *Hasher) Members() []string
- func (h *Hasher) Owner(key string) string
- func (h *Hasher) Place(key string, n int) []string
- func (h *Hasher) Prioritise(key string) []string
- func (h *Hasher) RemoveMembers(members ...string)
- func (h *Hasher) SetMembers(members ...string)
- type HasherOption
- type SortOrder
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Example (Ownership) ¶
h := rendezvous.NewHasher( rendezvous.WithMembers("node1", "node2", "node3", "node4", "node5"), ) fmt.Printf("The owner of item is %s\n", h.Owner("item"))
Output: The owner of item is node3
Example (PriorityList) ¶
h := rendezvous.NewHasher( rendezvous.WithMembers("node1", "node2", "node3", "node4", "node5"), ) fmt.Printf("priority list: %v\n", h.Prioritise("item"))
Output: priority list: [node3 node5 node1 node2 node4]
Example (Replication) ¶
h := rendezvous.NewHasher( rendezvous.WithMembers("node1", "node2", "node3", "node4", "node5"), ) fmt.Printf("the nodes to replicate data to are: %v\n", h.Place("item", 3))
Output: the nodes to replicate data to are: [node3 node5 node1]
func NewHasher ¶
func NewHasher(opts ...HasherOption) *Hasher
func (*Hasher) AddMembers ¶
AddMembers adds the given members to the member list
func (*Hasher) Owner ¶
Owner returns the best member for the given key sorted by their rendezvous hash value.
func (*Hasher) Place ¶
Place returns the top n members for the given key sorted by their rendezvous hash value.
func (*Hasher) Prioritise ¶
PriorityList returns all the placement members sorted by their rendezvous hash value for the given key.
func (*Hasher) RemoveMembers ¶
RemoveMembers removes the given members from the member list
func (*Hasher) SetMembers ¶
SetMembers replaces the current member list with the members provided
type HasherOption ¶
type HasherOption func(*Hasher)
func WithHashImplementation ¶
func WithHashImplementation(h hash.Hash) HasherOption
func WithMembers ¶
func WithMembers(members ...string) HasherOption
func WithSortOrder ¶
func WithSortOrder(order SortOrder) HasherOption
Click to show internal directories.
Click to hide internal directories.