consistenthash

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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

type Hash func(data string) uint64

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 onto a ring of tokens. Keys are mapped to the next node on the ring.

func New

func New(fn Hash, tokensPerNode int, initialNodes ...string) *Ring

New creates a new hash ring.

func (*Ring) AddNodes

func (r *Ring) AddNodes(nodes ...string)

func (*Ring) Hash

func (r *Ring) Hash(key string) string

func (*Ring) IsEmpty

func (r *Ring) IsEmpty() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL