Documentation
¶
Index ¶
Constants ¶
const DefaultTokensPerNode = 100
DefaultTokensPerNode is the default number of virtual nodes per node.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hash ¶
Hash is a function computing a 64-bit digest.
var DefaultHash Hash = xxhash.Sum64String
DefaultHash is the default Hash used by Ring.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring implements consistent hashing, aka. ring hash (not thread-safe). It hashes nodes and keys (strings) onto a ring of tokens. Keys are mapped to the next token (node) on the ring. Nodes cannot be removed. Instantiate a new Ring instead.
func New ¶
New creates a new hash ring with the given configuration and adds the given nodes. The given Hash (or DefaultHash if nil) is used to hash nodes and keys (strings). Each node is assigned tokensPerNode tokens (or DefaultTokensPerNode if <= 0) – aka. virtual nodes – for a more uniform key distribution.