Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type HasherFunc ¶
HasherFunc is the interface for any function that can act as a hasher.
type Hashring ¶
Hashring provides a ring consistent hash implementation using a configurable number of virtual nodes. It is internally synchronized and thread-safe.
func MustNewHashring ¶ added in v1.16.0
func MustNewHashring(hasher HasherFunc, replicationFactor uint16) *Hashring
MustNewHashring creates a new Hashring with the specified hasher function and replicationFactor.
replicationFactor must be >= 1 or this method will panic.
func NewHashring ¶
func NewHashring(hasher HasherFunc, replicationFactor uint16) (*Hashring, error)
NewHashring creates a new Hashring with the specified hasher function and replicationFactor.
replicationFactor must be > 0 and should be a number like 20 for higher quality key distribution. At a replicationFactor of 100, the standard distribution of key->member mapping will be about 10% of the mean. At a replicationFactor of 1000 it will be about 3.2%. The replicationFactor should be chosen carefully because a higher replicationFactor will require more memory and worse member selection performance.
func (*Hashring) Add ¶
Add adds an object that implements the Member interface as a node in the consistent hashring.
If a member with the same key is already in the hashring, ErrMemberAlreadyExists is returned.
func (*Hashring) FindN ¶
FindN finds the first N members in the hashring after the specified key.
If there are not enough members in the hashring to satisfy the request, ErrNotEnoughMembers is returned.